python-3.x

Vista User Access Controls with cx-freeze/python script

I'm trying to build a python script and freeze it with cx-freeze but with Vista User Access Control support. As it stands my script runs fine under Server 2003/Win XP, however I need to be able to write files into the root of a drive which requires elevated privileges under UAC. My compiled script is then executed by another process (s...

Python, With ... as ... AST/Symbol access

Disclaimer: Sensible semantics do dictate that the LHS of as behaving differently depending on the RHS lexeme is ludicrous. But I am curious nontheless. Hi guys, Simple question, but one that somone may be able to answer better than my hack. I'm currently messing with metaclasses etc and working out a comfortable syntax for some th...

how to decode HTTP request headers and body in Python 3?

i am writing an experimental asynchronous web server. i am wondering about the standard / 'best' way to decode HTTP requests in python? basically what reading from the socket gives me is a bytes representation of the incoming request raw data; how can i turn these into standard datatypes like dictionaries, lists of values, and so on? i...

Avoiding socket timeouts in SQLAlchemy

I'm new to SQLAlchemy, but I'm trying to use it to create and fill a database for a personal project. I've set pool_timeout to 43200 (twelve hours), but I'm still getting socket timeouts. engine = sqlalchemy.create_engine( 'postgresql+pg8000://gdwatson:pass@localhost/dbname', pool_timeout=43200) db.tables.meta.d...

Why Won't Komodo 6 Run or Debug Python 3 Code?

My problem: I try to debug some python 3 code. Komodo gives me this error message: "Komodo does not support execution of Python3 files through the debugger subsystem, please use a run command in the toolbox to process this file." then when I run 'run,' it gives me this error: "'run' is not recognized as an internal or external comma...

Python 3.x and SFTP

I know that the Paramiko api exists for Python 2.x. Is there an emerging method for interacting with a remote server using SFTP functions from within a Python 3.1 script? Extensive searching of the paramiko site uncovered no evidence of 3.x support. If not, I will either use Python-2.x with Paramiko for my remote access, or maybe just ...

UnicodeDecodeError on import of a .pyd file

Hi, I've started to slowly dabble with the Python/C API and after much fiddling and finagling, I was able to build a spam.pyd file. However, I must be missing something with this process and was hoping that someone could point me in the right direction. I thought that once spam.pyd was created, I could call it from Python via import sp...

Does readlines() return a list or an iterator in Python 3?

I've read in "Dive into Python 3" that "The readlines() method now returns an iterator, so it is just as efficient as xreadlines() was in Python 2". See here: http://diveintopython3.org/porting-code-to-python-3-with-2to3.html . I'm not sure that it's true because they don't mention it here: http://docs.python.org/release/3.0.1/whatsnew/3...

What substitutes xreadlines() in Python 3?

In Python 2, file objects had an xreadlines() method which returned an iterator that would read the file one line at a time. In Python 3, the xreadlines() method no longer exists, and realines() still returns a list (not an iterator). Does Python 3 has something similar to xreadlines()? I know I can do for line in f: instead of for ...

Script won't run in Python3.0

This script will run as expected and pass doctests without any errors in Python 2.6: def num_even_digits(n): """ >>> num_even_digits(123456) 3 >>> num_even_digits(2468) 4 >>> num_even_digits(1357) 0 >>> num_even_digits(2) 1 >>> num_even_digits(20) 2 """ count = 0 ...

python tkinter listbox: adding items

At program startup, I add some items to my listbox like this: for widget in WidgetNames: listbox.insert(0, widget) WidgetNames is obviously a list of some items, e.g. "Button" and "Canvas". The thing is, the listbox doesn't show the items that are added with above code. However, for widget in WidgetNames: listbox.insert(0, w...

Command-line arguments as bytes instead of strings in python3

Hello, I'm writing a python3 program, that gets the names of files to process from command-line arguments. I'm confused regarding what is the proper way to handle different encodings. I think I'd rather consider filenames as bytes and not strings, since that avoids the danger of using an incorrect encoding. Indeed, some of my file name...

How to access a MS SQL Server using Python 3?

I'm using a linux machine to make a little python program that needs to input its result in a SQL Server 2000 DB. I'm new to python so I'm struggling quite a bit to find what's the best solution to connect to the DB using python 3, since most of the libs I looked only work in python 2. As an added bonus question, the finished version o...

SQL to handle table updates in a "dynamically typed" fashion

I'm playing around with Python 3's sqlite3 module, and acquainting myself with SQL in the process. I've written a toy program to hash a salted password and store it, the associated username, and the salt into a database. I thought it would be intuitive to create a function of the signature: def store(table, data, database=':memory:') ...

Running piped subprocesses gives different result when the launch order changes ?

Hello, I'm running a pipe of commands from a python3 program, using subprocess.*; I didn't want to go trough a shell, for I'm passing arguments to my subcommands, and making sure these would not be misinterpreted by the shell would be nightmarish. The subprocess doc gives this example of how to do it: p1 = Popen(command1, stdout=PIPE)...

Is there a standard way to make sure a python script will be interpreted by python2 and not python3?

Is there a standard way to make sure a python script will be interpreted by python2 and not python3? On my distro, I can use #!/usr/bin/env python2 as the shebang, but it seems not all distros ship "python2". I could explicitly call a specific version (eg. 2.6) of python, but that would rule out people who don't have that version. It se...

Get defining class of unbound method object in Python 3

Say I want to make a decorator for methods defined in a class. I want that decorator, when invoked, to be able to set an attribute on the class defining the method (in order to register it in a list of methods that serve a particular purpose). In Python 2, the im_class method accomplishes this nicely: def decorator(method): cls = met...

How to make python 3 print() utf8

How to make python 3 (3.1) to print("Some text") to stdout in utf8 ... or how to output raw bytes.. Test.py TestText = "Test - āĀēĒčČ..šŠūŪžŽ" # this is UTF-8 TestText2 = b"Test2 - \xc4\x81\xc4\x80\xc4\x93\xc4\x92\xc4\x8d\xc4\x8c..\xc5\xa1\xc5\xa0\xc5\xab\xc5\xaa\xc5\xbe\xc5\xbd" # just bytes print(sys.getdefaultencoding()) prin...

New project Python 3x PostgreSQL 9x and pg8000 1x DBAPI?

I'm starting some new projects and want to know if pg8000 is considered a good choice for a production project? Obviously Python and PostgreSQL are mature products, but I'm concerned about pg8000 both when it comes to maturity and performance. Will my DB access suffer or will it be acceptable? So, please take some latitude in respondin...

Start app at startup in mac osx using python3?

An app created with python3 & pyqt needs to be executed on startup. Whenever the app gets executed it has to check whether it has been added to startup list, if not it should be added to the list so that by next time it should be executed on startup. Is there a way to initiate an apple script using python3 or python3 itself to acheive t...