Questions tagged [python-3.3]
For issues that are specific to Python 3.3. Use the more generic [python] and [python-3.x] tags where possible.
python-3.3
1,139
questions
447
votes
24
answers
1.0m
views
Python 3: ImportError "No Module named Setuptools"
I'm having troubles with installing packages in Python 3.
I have always installed packages with setup.py install. But now, when I try to install the ansicolors package I get:
importerror "No ...
217
votes
4
answers
86k
views
hash function in Python 3.3 returns different results between sessions
I've implemented a BloomFilter in python 3.3, and got different results every session. Drilling down this weird behavior got me to the internal hash() function - it returns different hash values for ...
148
votes
17
answers
340k
views
How to install pip for Python 3 on Mac OS X?
OS X (Mavericks) has Python 2.7 stock installed. But I do all my own personal Python stuff with 3.3. I just flushed my 3.3.2 install and installed the new 3.3.3. So I need to install pyserial again. I ...
101
votes
5
answers
56k
views
Import arbitrary python source file. (Python 3.3+)
How can I import an arbitrary python source file (whose filename could contain any characters, and does not always ends with .py) in Python 3.3+?
I used imp.load_module as follows:
>>> ...
95
votes
2
answers
61k
views
Return in generator together with yield
In Python 2 it used to cause an error when return occurred together with yield inside a function definition. But for this code in Python 3.3:
def f():
return 3
yield 2
x = f()
print(x.__next__()...
78
votes
9
answers
101k
views
How to use 2to3 properly for python?
I have some code in python 2.7 and I want to convert it all into python 3.3 code. I know 2to3 can be used but I am not sure exactly how to use it.
76
votes
5
answers
222k
views
Writing to CSV with Python adds blank lines [duplicate]
I am trying to write to CSV file but there are blank rows in between. How can I remove the blank rows?
import csv
b = open('test.csv', 'w')
a = csv.writer(b)
data = [['Me', 'You'],\
['293', '...
76
votes
4
answers
103k
views
AttributeError: 'module' object has no attribute 'request'
When I run the following code in Python 3.3:
import urllib
tempfile = urllib.request.urlopen("http://yahoo.com")
I get the following error:
I did this too to verify:
What am I doing wrong?
56
votes
7
answers
241k
views
Random word generator- Python
So i'm basically working on a project where the computer takes a word from a list of words and jumbles it up for the user. there's only one problem: I don't want to keep having to write tons of words ...
50
votes
5
answers
95k
views
Iterate over OrderedDict in Python
I have the following OrderedDict:
OrderedDict([('r', 1), ('s', 1), ('a', 1), ('n', 1), ('y', 1)])
This actually presents a frequency of a letter in a word.
In the first step - I would take the last ...
49
votes
2
answers
14k
views
Why is dictionary ordering non-deterministic?
I recently switched from Python 2.7 to Python 3.3, and it seems that while in Python 2 the ordering of dictionary keys was arbitrary but consistent, in Python 3 the ordering of the keys of a ...
48
votes
3
answers
28k
views
Is there official guide for Python 3.x release lifecycle?
I just noticed Python 3.2 was removed from the drop down selector in Python Docs. I have a framework using Python 3.3, so I'd like to know when it'll share the same fate, and move to a newer version ...
40
votes
1
answer
49k
views
Python3 - reload() can not be called on __import__ object?
Ok so for a number of reasons, I've been using s = __import__('parse') for the longest time in Python2, now I sorta need to being my transitions to Python3 for certain projects (mainly due to SSL).
...
39
votes
5
answers
55k
views
My scipy.misc module appears to be missing imsave
I open the python3 interpreter and type
import scipy.misc
scipy.misc.imsave
with the result
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: '...
39
votes
1
answer
13k
views
python: Is there a downside to using faulthandler?
Python 3.3 includes a module named faulthandler that displays helpful traceback information if a segfault occurs. (For Python versions prior to 3.3, the module can be obtained from PyPI.)
The module ...
37
votes
3
answers
56k
views
Format time string in Python 3.3
I am trying to get current local time as a string in the format: year-month-day hour:mins:seconds. Which I will use for logging. By my reading of the documentation I can do this by:
import time
'{0:%...
36
votes
12
answers
154k
views
Can't use chrome driver for Selenium
I'm having trouble using the Chrome driver for Selenium. I have the chromedriver downloaded and saved to C:\Chrome:
driver = webdriver.Chrome(executable_path="C:/Chrome/")
Using that gives me the ...
36
votes
4
answers
73k
views
Getting exception details in Python
I have to open & write to about 10 different files all within the same loop.
e.g:
for i in range(0,10):
try:
a=5
file1 = open("file1.txt",'w+')
file2 = open("file2.txt"...
36
votes
7
answers
25k
views
Can't catch mocked exception because it doesn't inherit BaseException
I'm working on a project that involves connecting to a remote server, waiting for a response, and then performing actions based on that response. We catch a couple of different exceptions, and behave ...
36
votes
2
answers
10k
views
whats the difference between python 3.3 and 3.3m [duplicate]
What's the difference between python 3.3 and 3.3m
I'm using Ubuntu 13.04 Raring and on my system I have python2.7 and python3.3 (I know the differences between 2 and 3)
But I also have installed ...
33
votes
4
answers
11k
views
Non-blocking multiprocessing.connection.Listener?
I use multiprocessing.connection.Listener for communication between processes, and it works as a charm for me. Now i would really love my mainloop to do something else between commands from client. ...
30
votes
5
answers
192k
views
Printing subscript in python
In Python 3.3, is there any way to make a part of text in a string subscript when printed?
e.g. H₂ (H and then a subscript 2)
30
votes
3
answers
24k
views
itertools.accumulate() versus functools.reduce()
In Python 3.3, itertools.accumulate(), which normally repeatedly applies an addition operation to the supplied iterable, can now take a function argument as a parameter; this means it now overlaps ...
30
votes
0
answers
3k
views
Does pyvenv replace virtualenv in python3.3 +? [duplicate]
I just read about pyvenv which is included in Python 3.3 per PEP 405.
It looks like it provides the same directory structure and the same usage as virtualenv. Is there some difference I'm missing or ...
28
votes
5
answers
32k
views
In Python 3.x make print work like in Python 2 (as statement)
I wonder if the print function can be made work (without changing the syntax all over the place) like in Python 2 and earlier.
So I have the statement like:
print "Hello, World!"
And I like ...
27
votes
7
answers
190k
views
SyntaxError: multiple statements found while compiling a single statement
I'm in Python 3.3 and I'm only entering these 3 lines:
import sklearn as sk
import numpy as np
import matplotlib.pyplot as plt
I'm getting this error:
SyntaxError: multiple statements found while ...
25
votes
3
answers
3k
views
Why do distribute and pip install to my virtualenv's ./local/bin?
I create and activate a virtualenv (venv) using Python 3.3's built-in way of doing it:
$ python3.3 -m venv env
$ source env/bin/activate
At this point python is the python in my virtualenv, which I ...
23
votes
6
answers
67k
views
ImportError: No module named '_sqlite3' in python3.3
sqlite3 error
import sqlite3
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.3/sqlite3/__init__.py", line 23, in <module>
...
23
votes
6
answers
19k
views
Using bisect in a list of tuples?
I'm trying to figure out how to use bisect in a list of tuples
for example
[(3, 1), (2, 2), (5, 6)]
How can I bisect this list according to the [1] in each tuple?
list_dict [(69, 8), (70, 8), ((65, ...
23
votes
4
answers
53k
views
How do I compile my Python 3 app to an .exe? [closed]
How do I convert my Python app to a .exe? I made a program with tkinter and was wondering how to make it possible for others to use. I use Python 3.3. I searched for a bit but could not find anything.
22
votes
2
answers
170k
views
SyntaxError: unexpected EOF while parsing
I have no idea why this does not work please help
import random
x = 0
z = input('?')
int(z)
def main():
while x < z:
n1 = random.randrange(1,3)
n2 = random.randrange(1,3)
...
22
votes
5
answers
33k
views
Installing pip for python3.3
I downloaded pip from Package Index > pip 1.2.1
Then I installed it using
sudo python3.3 setup.py install
Still, when I try to use pip-3.3 the terminal complains
-bash: pip-3.3: command not found
...
21
votes
5
answers
84k
views
Ubuntu - How to install a Python module (BeautifulSoup) on Python 3.3 instead of Python 2.7?
I have this code (as written in BS4 documentaion):
from bs4 import BeautifulSoup
When I run the script (using python3) I get the error:
ImportError: No module named 'bs4'
So installed ...
21
votes
3
answers
13k
views
subprocess and Type Str doesnt support the buffer API
I have
cmd = subprocess.Popen('dir',shell=True,stdout=subprocess.PIPE)
for line in cmd.stdout:
columns = line.split(' ')
print (columns[3])
have error in line 3 Type Str doesnt support the ...
21
votes
4
answers
50k
views
Modern GUI programming in Python 3.3
I am putting together a few programs, and it's about time to start making GUI's for some of them. The code is currently written in Python 3.3.
I have researched a few GUI's for Python, namely Tkinter,...
20
votes
5
answers
88k
views
'str' object has no attribute 'decode' in Python 3
I've some problem with decode method in python 3.3.4. This is my code:
for line in open('file','r'):
decodedLine = line.decode('ISO-8859-1')
line = decodedLine.split('\t')
But I can't decode ...
20
votes
2
answers
29k
views
Using Pillow with Python 3
I'm not having much luck using Pillow with Python 3.3.2 and I'd be grateful for some help. My problem is that after installing Pillow, I can't import Image.
My setup:
I've got Linux Mint 16 installed ...
19
votes
3
answers
40k
views
Removing everything except letters and spaces from string in Python3.3
I have this example string: happy t00 go 129.129 and I want to keep only the spaces and letters. All I have been able to come up with so far that is pretty efficient is:
print(re.sub("\d", "", 'happy ...
19
votes
2
answers
11k
views
Replace the content of dictionary with another dictionary in a function - Python
I have a dictionary, and I want to pass it as argument to a function. After executing this function, I want the dictionary changed.
Here is my try:
def func(dict):
dict = {'a': 5}
So what I ...
18
votes
5
answers
68k
views
Python count items in dict value that is a list
Python 3.3, a dictionary with key-value pairs in this form.
d = {'T1': ['eggs', 'bacon', 'sausage']}
The values are lists of variable length, and I need to iterate over the list items. This works:
...
18
votes
3
answers
19k
views
Download a zip file and extract it in memory using Python3
I would like to download a zip file from internet and extract it.
I would rather use requests. I don't want to write to the disk.
I knew how to do that in Python2 but I am clueless for python3.3. ...
18
votes
5
answers
50k
views
How to delete everything after a certain character in a string?
How would I delete everything after a certain character of a string in python? For example I have a string containing a file path and some extra characters. How would I delete everything after .zip? I'...
18
votes
6
answers
22k
views
Python 3.3 source code setup: modules were not found: _lzma _sqlite3 _tkinter
I am trying to set up the compiled version of CPython, on Ubuntu 12.04, by following the python developer guide.
Even after installing the dependent packages lzma and sqlite3, build fails indicating ...
18
votes
1
answer
2k
views
Does using virtualenvwrapper with Python3.3 mean I cannot (or should not) be using pyvenv?
Virtualenvwrapper is a user-friendly shell around Python's virtualenv.
Python 3.3 ships with pyvenv built into the standard library, which aims to supercede virtualenv.
But if I install ...
18
votes
3
answers
11k
views
A ThreadPoolExecutor inside a ProcessPoolExecutor
I am new to the futures module and have a task that could benefit from parallelization; but I don't seem to be able to figure out exactly how to setup the function for a thread and the function for a ...
17
votes
3
answers
5k
views
regex (vim) for print ... to print(...) for python2 to python3
This post is helpful only if you have strings inside of the print command.
Now I have tons of sourcecode with a statement such as
print milk,butter
which should be formatted to
print(milk,butter)
...
17
votes
3
answers
12k
views
Passing the library path as a command line argument to setup.py
modules = [Extension("MyLibrary",
src,
language = "c++",
extra_compile_args=["-fopenmp", "-std=c++11", "-DNOLOG4CXX"], # log4cxx is not ...
16
votes
2
answers
11k
views
Catching TimeoutExpired exception in Python 3.3
Sorry if this is a newbie question, but I'm having trouble catching the timeout exception in Python 3.3, running on win7, e.g.
import subprocess
try:
subprocess.call("ping -t localhost", timeout=3)...
16
votes
2
answers
22k
views
Writing a .CSV file in Python that works for both Python 2.7+ and Python 3.3+ in Windows
EDIT: I put it in the title, but just realized I didn't mention it in the body. This seems to be specific to Windows.
I'm having a hard time writing output using the csv Python module in a script ...
15
votes
2
answers
177k
views
Meaning of end='' in the statement print("\t",end='')? [duplicate]
This is the function for printing all values in a nested list (taken from Head first with Python).
def printall(the_list, level):
for x in the_list:
if isinstance(x, list):
...