python-3.x

what functional tools remain in Python 3k?

I have have read several entries regarding dropping several functional functions from future python, including map and reduce. What is the official policy regarding functional extensions? is lambda function going to stay? ...

What does Python's builtin __build_class__ do?

In Python 3.1, there is a new builtin function I don't know in the builtins module: __build_class__(...) __build_class__(func, name, *bases, metaclass=None, **kwds) -> class Internal helper function used by the class statement. What does this function do? Why must it be in builtins if it's internal? What is the difference to ...

Invalid Token when using Octal numbers.

Hi, I'm a beginner in python and I'm trying to use a octal number in my script, but when I try it, it returns me that error: >>> a = 010 SyntaxError: invalid token (<pyshell#0>, line 1) >>> 01 SyntaxError: invalid token (<pyshell#1>, line 1) There's something wrong with my code? I'm using Python3 (and reading a python 2.2 book) ...

What is internal representation of string in Python 3.x

In Python 3.x, a string consists of items of Unicode ordinal. (See the quotation from the language reference below.) What is the internal representation of Unicode string? Is it UTF-16? The items of a string object are Unicode code units. A Unicode code unit is represented by a string object of one item and can hold either a ...

Get webpage contents with Python?

I'm using Python 3.1, if that helps. Anyways, I'm trying to get the contents of this webpage. I Googled for a little bit and tried different things, but they didn't work. I'm guessing that this should be an easy task, but...I can't get it. :/. import urllib.request page = urllib.request.urlopen('http://hiscore.runescape.com/index_lite....

[Python] Strings are wrapped in b'...'

import urllib.request #name = input("What is your screenname? "); name = "zezima" page = urllib.request.urlopen('http://hiscore.runescape.com/index_lite.ws?player=' + name) page = page.readlines() skills = [] for line in page: skills += [line] print(skills) Outputs: [[b'478,2372,1224928266\n'], [b'458,99,59502162\n'], [b'262,99...

Why is this invalid syntax?

Why is this complaining about an invalid syntax? #! /usr/bin/python recipients = [] recipients.append('[email protected]') for recip in recipients: print recip I keep getting: File "send_test_email.py", line 31 print recip ^ SyntaxError: invalid syntax ...

Working with bit streams

I have a base64 encoded bit stream, I want to work with. After decoding it with base64.b64decode I get a bytes object (Py3k btw) containing the decoded code. The problem is now, that I would like to work on that bytes object with bit-wise operations, such as shifting, bit wise and etc, but that is not possible as it is a bytes sequence. ...

Supporting different versions of Python

This subject has been disturbing me for some time. For my Python project I wanted to be able to support Python versions 2.4 to 3.1. I thought a bit about how to do this, and eventually decided to have four separate forks of the source code for four different versions of Python: 2.4, 2.5, 2.6 and 3.1. I have come to view that as a bad d...

Does Subversion *Really* Require ActivePython?

It is listed as a requirement, but I'd rather not install it since I already have Python 3.1.1 installed. If I must, are there any issues with the two Python versions co-existing (on Windows)? From the ReadMe: http://www.collab.net/nonav/downloads/subversion/readme/svn1.6%5Fserver%5Fclient%5Fwindows.html CollabNet Subversion Server and...

python byte to "unsigned 8 bit integer"

hi i am reading in byte array/list from socket... but now i want python to treat the first byte as "unsigned 8 bit integer". how is this possible? and how is it possible to get its integer value as unsigned 8 bit integer? thanks in advance! ...

python string as hex terminated with null

I receive strings in their hex format, i.e. s = "0x0ff" or s = "0fd" how can I check whether the above type of strings are null terminated or not? thanks! ...

Testing subpackage modules in Python 3

I have been experimenting with various uses of hierarchies like this and the differences between absolute and relative imports, and can't figure out how to do routine things with the package, subpackages, and modules without simply putting everything on sys.path. I have a two-level package hierarchy: MyApp __init__.py ...

Item assignment on bytes object in Python

GAHH, code not working is bad code indeed! in RemoveRETNs toOutput[currentLoc - 0x00400000] = b'\xCC' TypeError: 'bytes' object does not support item assignment How can I fix this: inputFile = 'original.exe' outputFile = 'output.txt' patchedFile = 'original_patched.exe' def GetFileContents(filename): f = open(filename, ...

Custom (interactive) shell with Python

I'm currently trying to make some small shell-like utility for a custom script I wrote, so I can easily work with it (it's rather simple, so an interactive shell would be perfect). Do you have any resources for me on how to create a shell in Python? I spent googling for a while, but all I could find was information about IDLE and simila...

Py2exe: Embed static files in exe file itself and access them

Hi all, I found a solution to add files in library.zip via: Extend py2exe to copy files to the zipfile where pkg_resources can load them. I can access to my file when library.zip is not include the exe. I add a file : text.txt in directory: foo/media in library.zip. And I use this code: import pkg_resources import zipfile from cStrin...

Tab completion with Python's Cmd.cmd

After testing a while with the Cmd.cmd framework in python, I noticed a problem I don't know what to do about. Plus I believe to have this working some hours before (or I'm just crazy), so this is even more weird. I have the following example code, tested on both Windows and Linux systems (so it's not a Windows problem), but tab complet...

Inheriting Custom Operators in Python?

If I have class A that defines __cmp__, and class B that extends class A, it seems like I have to redefine __cmp__ in class B. Is this correct? Is there a better workaround than implementing a method "cmp" in class A and calling it from the separate implementations of __cmp__ in class A and class B? Thanks, -aj UPDATE: The issue s...

install pyquery on windows

Hi! I want to install pyquery on windows. But i cant run setup.py install on the command line. Do you have any hint? ...

PyWin32: Windows Classic theme

In the PyWin32 demos folder, the win32gui_dialog.py sample uses the classic windows controls. Can the Windows Vista themed buttons also be displayed using PyWin32, and if so, how? I'm using ActivePython 3.1, if that makes any difference. Sample: ...