python

sftp using ftplib

Hi All I need to download a file from a host using sFTP. Do you know if is it possible to do that using python ftplib? I saw an example here, but when I try to connect I receive EOFError. I tried this code: import ftplib ftp = ftplib.FTP() ftp.connect( "1.2.3.4", "22" ) This method returns with an error after long time so I cannot p...

python list that matches everything

I probably didn't ask correctly: I would like a list value that can match any list: the "inverse" of (None,) but even with (None,) it will match item as None (which I don't want) The point is I have a function working with: [x for x in my_list if x[field] not in filter_list] and I would like to filter everything or nothing without maki...

Error when install python mysql module on windows?

When i try to install mysql on windows i get this error MySQL-python-0.9.2>python setup.py build running build running build_py running build_ext building '_mysql' extension error: Unable to find vcvarsall.bat ...

Python basic maths

My friend wrote up this script for me to calculate the quantity of construction materials needed for a theoretical site. It basically takes 2 numbers and increases them independently until the large number reaches 50,000. It then prints a list like this: 20000:6.40,21000:6.61,22000:6.82,23000:7.03,24000:7.24,25000:7.45,26000:7.66,2700...

cross module variable

from here I got an idea about how using variables from other modules. this all works fine with import foo as bar But I don't want to import my modules as "bar" I want to use it without any prefix like from foo import * Using this it´s impossible to modify variables from other modules. reading will work! any idea? suggestions? ...

Python inserting a short integer into a list of bytes

Hi I have a list of bytes as follows pkt_bytes = [ 0x02,0x07, 0xff,0xff ,0x00,0x03] in the position 0xff,0xff I want to put a 16bit short integer How do I do it Regards ...

How do I sort this list ?

I have a list of lists. List<List<T>> li = { {a1,a2,a3 ... aN}, {b1,b2,b3 ... bN}, ... }; double foo(List<T> list) { // do something // e.g {1,2,3} // it = 1 + 2 + 3 return it; } Now I want to sort li in such a way that higher the foo(x) for a x higher it should appear in a sorted list. What is the best w...

python json unicode - how do I eval using javascript

Really spent a lot of time searching for this. Please need some help. I am trying to add multilingual feature to my web app framework. For this I am unable to send non ascii characters as JSON. Here is what I am doing Here is what I get from the database '\xe0\xa4\xa4\xe0\xa5\x87\xe0\xa4\xb8\xe0\xa5\x8d\xe0\xa4\xa4' which when I pri...

Get fully qualified class name of an object in python

For logging purposes I want to retrieve the fully qualified class name of a Python object. (With fully qualified I mean the class name including the package and module name.) I know about x.__class__.__name__, but is there a simple method to get the package and module? ...

Increment a VERSION ID by one and write to .mk file

Hello, I have code to read in the version number from a make file. VERSION_ID=map(int,re.match("VERSION_ID\s*=\s*(\S+)",open("version.mk").read()).group(1).split(".")) This code takes VERSION_ID=0.0.2 and stores it as [0, 0, 2]. Is there any way I can increment this number by one and write the new version number into the version.mk ...

SWIG Python bindings for OpenCV 2.0 with MacPorts

Y'all, I've been at to for 3 days trying to get OpenCV Python binds happening, and I have (the full epic struggle is documented here) but despite turning the SWIG flag on in CMake after installing swig via macports, I'm not getting any SWIG action :( My cmake command looks like: cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFI...

Compilation warning in Python

when a python file is compiled in linux machine the following warning is seen but the same file compiled in Solaris machine, warning is not seen /opt/swe/tools/ext/gnu/python-2.3.5_p1/i686-linux2.4/lib/python2.3/config/libpython2.3.a(posixmodule.o)(.text+0x3e9a): In function `posix_tmpnam': ./Modules/posixmodule.c:6138: warning: the use...

how do i get the byte count of a variable in python just like wc -c gives in unix

hi all , i am facing some problem with files with huge data. i need to skip doing some execution on those files. i get the data of the file into a variable. now i need to get the byte of the variable and if it is greater than 102400 , then print a message. update : i cannot open the files , since it is present in a tar file. ...

How do I send a mail via mailx & subprcoess?

Hello all. I am EE, trying to write a script to simplify file checks using Python. For some reason, our IT will not let me gain access to our smtp server, and will only allow sending mail via mailx. So, I've thought of running mailx from Python and send it, in the same way that it works in my console. Alas, it gives an exeption. See Lin...

In Python how should I test if a variable is None, True or False

I have a function that can return one of three things: success (True) failure (False) error reading/parsing stream (None) My question is, if I'm not supposed to test against True or False, how should I see what the result is. Below is how I'm currently doing it: result = simulate(open("myfile")) if result == None: print "error p...

How powerful is x3d for making animations?

I want to make a rotating drillbit animation that shows the complete process of drilling. I am not really sure that it can be done using x3d. How good is x3d (along with python scripting, maybe) to make such animations? ...

Python based web reporting tool?

I have a question for those of you doing web work with python. Is anyone familiar with a python based reporting tool? I am about to start on a pretty big web app and will need the ability to do some end user reporting (invoices, revenue reports, etc). It can be an existing django app or anything python based so I can hook into it. Thank...

How do I execute (not import) a python script from a python prompt?

I need to execute a Python script from an already started Python session, as if it were launched from the command line. It should be similar to doing source in bash or sh. ...

Download file using urllib in Python with the wget -c feature

Hello, I am programming a software in Python to download HTTP PDF from a database. Sometimes the download stop with this message : retrieval incomplete: got only 3617232 out of 10689634 bytes How can I ask the download to restart where it stops using the 206 Partial Content HTTP feature ? I can do it using wget -c and it works pret...

How do I get Sphinx to test code embedded in documentation?

If this code is a blockquote in my documentation, what do I need to do to make Sphinx run it when the documentation is generated? I tried adding .. testcode:: import datetime def today(): return datetime.datetime.now().date() if True: today() to one of the .rst sources and the Sphinx doctest extension to c...