python-3.x

Strings in Python 3

Hi: I am programing VIX API from python 2.5, but now I want to port the code to python 3.2 This funtion opens the virtual machine: self.jobHandle = self.VixLib.vix.VixVM_Open(self.hostHandle, "C:\\MyVirtualMachine.vmx", None, None)e...

Is it safe to replace MacOS X default python interpreter ?

Hi guys, i'm new to the Mac OS X world so i have to ask you this. I have the default python 2.6.1 installed as /usr/bin/python and the 3.1.2 as /usr/local/bin/python3.1 . Considering that i use only 3.x syntax, is it safe to replace the default interpreter (2.6) with the 3.1 one (python-config included) using symlinks (and removing old ...

How to call an executable as independent process using python in windows

After calling an exe using python script in windows, the exe should run independent of this python script and once it is initiated the control should comeback to python script and executes the further script and control of .py file will die. But on other side before finishing execution, the exe should call this python script. Ideas woul...

WSGI request and response wrappers for Python 3

Are there WSGI request and response wrappers for Python 3? WebOb looks nice (although there is some critique), but it seems to be written in Python <3. Werkzeug seems also to be written in Python <3. Should I write my own request and response wrappers for Python 3? Maybe this would be impossible, since WSGI seems to be somewhat broke...

Python circular dependency import

Say I have three files like this: testimports module: #import moduleTwo import moduleOne hiString = "Hi!" moduleOne.sayHi() moduleOne: import moduleTwo class sayHi(): moduleTwo.printHi() moduleTwo: import testimports def printHi(): print(testimports.hiString) If I run testimports, I get the following: Traceback (mo...

How to strip all whitespace from string

How do I strip all the spaces in a python string? For example, I want a string like strip my spaces to be turned into stripmyspaces, but I cannot seem to accomplish that with strip(): >>> 'strip my spaces'.strip() 'strip my spaces' ...

Adding optional parameters to the constructors of multiply-inheriting subclasses of built-in types?

My multiple-inheritance-fu is not strong. I am trying to create a superclass whose __init__ takes an optional named parameter and subclasses of it which also inherit from built-in types. Sadly, I appear to have no idea how to make this work: >>> class Super(object): name = None def __init__(self, *args, name=None, **kwargs): ...

packing and unpacking variable length array/string using the struct module in python

Hi, I am trying to get a grip around the packing and unpacking of binary data in Python 3. Its actually not that hard to understand, except one problem: what if I have a variable length textstring and want to pack and unpack this in the most elegant manner? As far as I can tell from the manual I can only unpack fixed size strings dire...

Python - Qt. How to make a Terminal Window for Telnet or ssh server interaction.

Hi, i am making a PyQt application, and i want to make something like a Terminal Window, where the user can interact with a Telnet or ssh server. My first idea was to have a Window with a black QPlainTextEdit and a scrollbar. I am new to python-Qt world and would appreciate some guidance. Any ideas? Thanks :-) ...

Python: binary tree traversal iterators without using conditionals

I am trying to create a module in python for iterating over a binary tree using the 4 standard tree traversals (inorder, preorder, postorder and levelorder) without using conditionals and only using polymorphic method dispatch or iterators. The following examples should work. for e in t.preorder(): print(e) for e in t.postorder(): ...

python 3.1 - DictType not part of types module?

This is what I found in my install of Python 3.1 on Windows. Where can I find other types, specifically DictType and StringTypes? >>> print('\n'.join(dir(types))) BuiltinFunctionType BuiltinMethodType CodeType FrameType FunctionType GeneratorType GetSetDescriptorType LambdaType MemberDescriptorType MethodType ModuleType TracebackType _...

Writing a module for both Python 2.x and 3.x

I've written a pure-Python module for Python 3.0/3.1 which I'd also like to make it compatible with 2.x (probably just 2.6/2.7) in order to make it available to the widest possible audience. The module is concerned with reading and writing a set of related file formats, so the differences between 2.x and 3.x versions would be slight — e...

Views in Python3.1?

What exactly are views in Python3.1? They seem to behave in a similar manner as that of iterators and they can be materialized into lists too. How are iterators and views different? ...

Python3 int, long unification implementation

I just read through a PEP concerning the unification of ints and longs in Python3k in PEP 237. The approach used in this seems very interesting. The approach is to create a new type "integer" which is the abstract base class of int and long. Also, performing operations on ints which result in very large numbers will no longer result in a...

How to install a Python Recipe File (.py)?

I'm new to Python. I'm currently on Py3k (Win). I'm having trouble installing a .py file. Basically, i want to use the recipes provided at the bottom of this page. So i want to put them inside a .py and import them in any of my source codes. So i copied all the recipes into a recipes.py file and copied them to C:\Python3k\Lib\site-pack...

Webserver on python3

I've create a web app in Python3 all runs beautiful till that day what i have to upload a file... theres no way to find the path or the file in the environ i am using wsgi and i am thinking to migrate to another thing, what are your recommendation? ...

Problems with cgi.FieldStorage

I have an application, what uses wsgi as middleware, everything it's ok, with the Get but, in the POST using a form i am facing a big problem, i don' t find nothing, no matter what i make theenviron['CONTENT-TYPE'] give me this:multipart/form-data; boundary=---------------------------8753104564381071051372446876, the cgi.FieldStroage giv...

Problems with form and POST

Hello, i am facing problems with my form, i wrote a app in Python3.1 and when i make a GET or a POST via AJAX works pefectly but when i' ve try to do the same thing with the form-way the environ['wsgi.input'] give me this: -----------------------------4974611941277794205934495116--\r in the first time i think this was because the file...

strange python behaviour with mixing globals/parameters and function named 'top'

The following code (not directly in an interpreter, but execute as file) def top(deck): pass def b(): global deck produces the error SyntaxError: name 'deck' is local and global on python2.6.4 and SyntaxError: name 'deck' is parameter and global on python 3.1 python2.4 seems to accept this code, so does the 2.6.4 inter...

compress a string in python 3 ?

I don't understand in 2.X it worked : import zlib zlib.compress('Hello, world') now i have a : zlib.compress("Hello world!") TypeError: must be bytes or buffer, not str How can i compress my string ? Regards Bussiere ...