python-3.4

Porting to Python3: PyPDF2 mergePage() gives TypeError

烂漫一生 提交于 2019-12-05 22:00:35
I'm using Python 3.4.2 and PyPDF2 1.24 (also using reportlab 3.1.44 in case that helps) on windows 7. I recently upgraded from Python 2.7 to 3.4, and am in the process of porting my code. This code is used to create a blank pdf page with links embedded in it (using reportlab) and merge it (using PyPDF2) with an existing pdf page. I had an issue with reportlab in that saving the canvas used StringIO which needed to be changed to BytesIO, but after doing that I ran into this error: Traceback (most recent call last): File "C:\cms_software\pdf_replica\builder.py", line 401, in merge_pdf_files

Invalid syntax using regular expression in python 3.4

£可爱£侵袭症+ 提交于 2019-12-05 21:00:23
I am using the following expression in python 3.4 it gives syntax error but the same code works in python 2.7 block = re.compile(ur'DATA\(value\)[\S ]+\s((?:(?![^\n]+DATA\(value2\)).)*)', re.IGNORECASE | re.DOTALL) I am unsure what is the real issue in this expression Python 3 has no ur'...' raw unicode string syntax. Use r'...' instead: block = re.compile( r'DATA\(value\)[\S ]+\s((?:(?![^\n]+DATA\(value2\)).)*)', re.IGNORECASE | re.DOTALL) If you need to create cross-Python compatible code, you'll have to use conditional code that'll decode the byte string produced by r'...' to a unicode

Grab any exception in PyQt

浪子不回头ぞ 提交于 2019-12-05 15:44:41
I've created an GUI app in PyQt, which I want to share with many people. Sometimes I get unexpected exceptions and I take it for granted - after every exception I improve my code and it gets better and better. I use a logger for recording these exceptions and special hook for PyQt silenced exceptions. My code looks like this: Logger def setLogger(level=logging.DEBUG, name="my_logger", file=join("src", "log.out")): logger = logging.getLogger(name) logger.setLevel(level) # console logger ch = logging.StreamHandler() console_lvl = logging.DEBUG ch.setLevel(console_lvl) formatter = logging

Couldn't create working virtual environment for Python 3.4

大兔子大兔子 提交于 2019-12-05 12:48:19
I installed Python 3.4.2 and Virtualenv 12.0.5 in my Linux Mint 17.1 Then I tried creating: $ virtualenv venv And also using --clear and/or -p /usr/bin/python3.4, always getting the messages: Using base prefix '/usr' New python executable in venv/bin/python3 Also creating executable in venv/bin/python ERROR: The executable venv/bin/python3 could not be run: [Errno 13] Permission denied Another try was: $ pyvenv-3.4 venv It gave no errors on creation, but in the venv/bin file the python3.4 is a symbolic link to /usr/local/bin/python3.4. Then when I activate and install any lib using pip or pip3

Preferred block size when reading/writing big binary files

↘锁芯ラ 提交于 2019-12-05 05:53:17
I need to read and write huge binary files. Is there a preferred or even optimal number of bytes (what I call BLOCK_SIZE ) I should read() at a time? One byte is certainly too little, and I do not think reading 4 GB into the RAM is a good idea either - is there a 'best' block size? or does that even depend on the file-system (I'm on ext4 )? What do I need to consider? Python's open() even provides a buffering argument. Would I need to tweak that as well? This is sample code that just joins the two files in-0.data and in-1.data into out.data (in real life there is more processing that is

Python relative import with more than two dots

女生的网名这么多〃 提交于 2019-12-05 05:25:31
Is it ok to use a module referencing with more than two dots in a path? Like in this example: # Project structure: # sound # __init__.py # codecs # __init__.py # echo # __init__.py # nix # __init__.py # way1.py # way2.py # way2.py source code from .way1 import echo_way1 from ...codecs import cool_codec # Do something with echo_way1 and cool_codec. UPD: Changed the example. And I know, this will work in a practice. But is it a common method of importing or not? From PEP8 : Absolute imports are recommended, as they are usually more readable and tend to be better behaved (or at least give better

Why does IDLE 3.4 take so long on this program?

人走茶凉 提交于 2019-12-05 03:42:51
This question was migrated from Code Review Stack Exchange because it can be answered on Stack Overflow. Migrated 5 years ago . EDIT: I'm redoing the question entirely. The issue has nothing to do with time.time() Here's a program: import time start=time.time() a=9<<(1<<26) # The line that makes it take a while print(time.time()-start) This program, when saved as a file and run with IDLE in Python 3.4, takes about 10 seconds, even though 0.0 is printed out from time.time() . The issue is very clearly with IDLE, because when run from the command line this program takes almost no time at all.

Installing numpy for Python 2.7 while also having Python 3.4 installed?

余生颓废 提交于 2019-12-05 01:23:20
I have both Python 2.7 and Python 3.4 (and have to have both because for the class I'm running, students have the option of using either). One student has used Python 2.7 and numpy for their project, but when I attempt to install numpy, it installs it to 3.4. I need to install it to 2.7. I'm using numpy 1.9 from this site, which I'm told is also 2.7-specific: http://sourceforge.net/projects/numpy/files/NumPy/ However, nonetheless it still goes to the 3.4 folder. Copying it to Python 2.7 didn't work, obviously. How do I do this? I recommend installing with pip. pip install numpy If this doesn't

Hide some maybe-no-member Pylint errors

浪尽此生 提交于 2019-12-05 00:43:51
The following Python fragment code gets analyzed by Pylint : if type(result) is array.array: read = result.tobytes() ... with the following error for the last line: E:401,22: Instance of 'int' has no 'tobytes' member\ (but some types could not be inferred) (maybe-no-member) The result variable is received from an external function. How can I change (correct) the code to make Pylint understand? Or how can I tell it that the result of the function can have other types than int? Or how can I tell it to ignore that particular line? (I favor an answer in this order of the questions) sthenault For

How to install xmlrpclib in python 3.4?

时光总嘲笑我的痴心妄想 提交于 2019-12-04 23:18:22
When I am trying to install xmlrpclib, I am getting following error in python version 3.4 Downloading/unpacking xmlrpclib Could not find any downloads that satisfy the requirement xmlrpclib Some externally hosted files were ignored (use --allow-external xmlrpclib to allow). Cleaning up... No distributions at all found for xmlrpclib Storing debug log for failure in /home/shiva/.pip/pip.log How to install xmlrpclib in python 3.4 ? xmlrpclib is part of the standard library in Python 2.x. It's not a package that you need to install. In Python 3.x you can import it from xmlrpc instead: https://docs