Re: Why Python forbids multiple instances of one module?
Why Python forbids multiple instances of one module? If only Python allows multiple instances of one module, module will be enough to replace class in most cases. After all, it is much easier to write a module than a class, at least we do not have to write self everywhere. If you really want to do that, it should be possible by deleting the entry from sys.modules and re-importing it. You save yourself having to explicitly write self everywhere, but instead you have to declare all your instance variables as globals in each method that uses them, which isn't much less of a chore. You also lose inheritance, properties (and descriptors in general), magic method support, metaclasses, and pretty much all the other nice features that new-style classes have to offer. Wow, it works! Thanks a lot for the good idea. It is cool to write, test, debug and maintain POP codes, while realizing the OOP power. I think inheritance might be simulated with: from parentModule import * I really expect for the day when operator overloading and new-style class features find their way into module. Thans again.-- http://mail.python.org/mailman/listinfo/python-list
Why Python forbids multiple instances of one module?
Why Python forbids multiple instances of one module? If only Python allows multiple instances of one module, module will be enough to replace class in most cases. After all, it is much easier to write a module than a class, at least we do not have to write self everywhere. -- http://mail.python.org/mailman/listinfo/python-list
Re: help req debugging python and c together
Hi, I am working in gnuradio compiler. I need some help in debugging python and c together. By this i mean that i have written some blocks in c that are connected together using python. So i need to debug ( breakpoints ect ) python such that when a specific c block is called at the back end (in python script ) the debugger takes me into the c code and after that switches back to python and so on. Thanks in advance. Regards, Sanam PythoidC ( http://pythoidc.googlecode.com or http://pythoidc.sf.net ) is a C language tool for Python, C code and Python code coexist in the same IDE or even the same file, thus avoids most of the switches in debugging python and c together. -- http://mail.python.org/mailman/listinfo/python-list
copy some files from IE temporary internet files
Hi friends, I want to program Python to copy some video files (.flv) from the IE folder temporary internet files, but os.listdir('C:\\Documents and Settings\\Administrator\\Local Settings\\Temporary Internet Files') seemed unable to find any video file (although they really exist and can be manually copied with Windows explorer). I googled and found that temporary internet files is not a normal folder. Will any friend tell me how to do this? ChenGuang-- http://mail.python.org/mailman/listinfo/python-list
Re: getting a string as the return value from a system command
Catherine Moroney wrote: Hello, I want to call a system command (such as uname) that returns a string, and then store that output in a string variable in my python program. What is the recommended/most-concise way of doing this? I could always create a temporary file, call the subprocess.Popen module with the temporary file as the stdout argument, and then re-open that temporary file and read in its contents. This seems to be awfully long way of doing this, and I was wondering about alternate ways of accomplishing this task. In pseudocode, I would like to be able to do something like: hostinfo = subprocess.Popen(uname -srvi) and have hostinfo be a string containing the result of issuing the uname command. Thanks for any tips, Catherine import os txt = os.popen(uname -srvi) hostinfo = txt.readline() Or if the command outputs a number of lines (such as 'ls'), use txt.readlines() to put the result into a list of strings. -=- Larry -=- os.popen3() gives not only result but also error prompt (in case an error or warning happens) stdin,stdout,stderr = os.popen3('uname -srvi') resultText = stdout.read() errorText = stderr.read() For more examples of os.popen3() please look at source code of PythoidC (http://pythoidc.googlecode.com or http://pythoidc.sf.net )-- http://mail.python.org/mailman/listinfo/python-list
Re: finding objects in a piece of functional code ?
PythoidC (http://pythoidc.googlecode.com or http://pythoidc.sf.net ) took the similar technique finding objects in a piece of functional C code with Python In the thread Re: braceless and semicolonless, I discussed some details. May be of some help. - Original Message - From: Stef Mientki To: python-list@python.org Sent: Sunday, April 11, 2010 12:08 AM Subject: finding objects in a piece of functional code ? hello, I would like to translate some functional description into some standard class object, so it can be used as a basic building brick into a larger piece of code. Suppose the functional description is: Name = 'Test_Function' Out = 3 * In That's all I would like to write. So it should be translated into something : class Test_Function ( basic_buidling_brick ) : Orginal_Description = Name = 'Test_Function' Out = 3 * In def Run ( self, Inputs ) : Output = 3 * Input return Output One of the tasks is to find all objects in the functional code., so the translator can ask additional information for input/output/memory variables. The best I can think of is something like this: my={} my2=copy.copy(my) exec('A=3; B=4; C=A*B; print A,B,C',my) 3 4 12 for item in my : ... if item not in my2 : ... print item ... __builtins__ A C B But this doesn't work, if I use a not yet definied variable (like In in the example above). Are there better ways ? Or even better are there programs or libraries that can perfom such a translation ? thanks, Stef Mientki -- http://mail.python.org/mailman/listinfo/python-list
Re: braceless and semicolonless
Hi Peter, In PythoidC, I handled C header files (and other C files for INCLUDE) with Python regular expression (RE). First, I use the following RE to break C header files or C files into pieces sepRE=_re.compile(r'\; | \{ | \} | // | /\* | \*/ | \r?\n',_re.VERBOSE) Then, I carefully designed a loop testing each of the seperaters between adjacent pieces for sep in sepRE.finditer(f0c): ... if sg==';': cItems.append(f0c[span0:ss1].strip()) span0 = ss1 ... to reassemble several (may be one) consequent pieces into items (a function, a struct, a constant ...) At last I classify the items with some REs like structRE=_re.compile(r'^(struct\s+([0-9A-Za-z_]+)\s*\{.+\}.*\;)$',_re.IGNORECASE|_re.DOTALL) and arranged the items into Python objects with setattr(...) You can download and read the source code of PythoidC at http://pythoidc.sf.net or http://pythoidc.googlecode.com If you feel PHP not good enough, I'd like to suggest Python ( www.python.org ). Python is really an excellent language, with Python you can program softwares for almost any porpose (except for hardware drivers and some software with very high requirement of speed, now PythoidC is just the extension for Python in such areas ). Welcome to join the Python mailing list http://mail.python.org/mailman/listinfo/python-list to discuss Python techniques, there are many warm-hearted friends willingly to answer almost any questions. By the way, I work in China Medical University, Shenyang, northeast China. Will you tell me something about youself? Best Regards, ChenGuang 2010-04-09 22:24:27,Peter West peterjwe...@googlemail.com : Hi Chen, My project uses a tree structured linked list to break down PHP into chunks, It was necessary because PHP has a lot of syntaxes for strings. Some parts of the language like one line comments and heredocs were quite a lot of trouble. How have you handled the pre-processor? I briefly considered modifying my project for C but the pre-processor's features would be difficult to handle. I'll try to find you an example. What other features would you like to add? In PHP I'm trying to add some useful syntaxes such as calling an index of an array without assigning the array to a variable e.g. $object-getArray()[0]. Another is instantiating an object and using it in the same statement e.g. ($object new Class)-method(). Unfortunately PHP is not a very good language and there are only a few things I can change about it. Peter. 2010/4/9 CHEN Guang dr...@126.com Dear Peter, I am the developer of PythoidC (braceless and semicolonless C language). I am so glad to see your message, just like a message from Voyager 2 spacecraft, telling me that I am nolonger alone in the universe! My plan is to release new versions of PythoidC from time to time, adding new applications and more examples. My hope is that our ideal (braceless and semicolonless) will be shared by more people in the world, thus lead to the simplification of all computer languages (Java, Perl ...) Let's talk often. ChenGuang -- http://mail.python.org/mailman/listinfo/python-list
Re: SIP
PythoidC ( http://pythoidc.sf.net ) provides some examples and templates for writing and importing C modules (.c or .exe) into Python environment, may be of some help. - Original Message - From: omnia neo neo.omn...@gmail.com To: python-list@python.org Sent: Friday, April 09, 2010 1:51 PM Subject: Re: SIP On Apr 9, 10:42 am, omnia neo neo.omn...@gmail.com wrote: On Apr 9, 10:30 am, Stefan Behnel stefan...@behnel.de wrote: omnia neo, 09.04.2010 07:01: import siptest I get following error : import error : no module named siptest Is the directory where your siptest.dll lies in your PYTHONPATH (sys.path)? Otherwise, Python can't find it. Stefan thanks for reply Stefan.. well I added PYTHONPATH = my dll path in my environment variables (windows XP). well I just tried this too. I added the path using sys.path on the fly in my python script as follows: ### import sys sys.path.append(dll path) print sys.path import siptest ### again same error: ImportError: No module named siptest. -- http://mail.python.org/mailman/listinfo/python-list
Re: Loading an imported module (C API)
PythoidC (http://pythoidc.sourceforge.net/) provides an easy way for developing and importing C modules into Python environment. There are some examples, may be of some help to you. With PythoidC, Python programmers can write, debug, commpile, C codes all in Python IDE, and do not have to tackel the boring braces {} and line-end semicolons ; PythoidC automatically parses C header files, make corresponding Python objects, thus Python programmer can essily introspect into C ... ... CHEN Guang - Original Message - From: booncw chiaw...@gmail.com To: python-list@python.org Sent: Tuesday, April 06, 2010 9:58 PM Subject: Loading an imported module (C API) Hi, I am running a simulation where the python module has already been imported. Could you please tell me how to load it? I've been doing this (importing everytime), but it is too slow: pModule = PyImport_Import(pName); Yours, Boon -- http://mail.python.org/mailman/listinfo/python-list
Re:Re: C++ code generation
Plug? Any evidence to say that? As long as this thread concerned, is there any answer more closed to the topic C++ code generation than mine? I think Stefan was telling you, in a nice way, to stop spamming every thread about code generation with a plug for your project. 2010/3/17 CHEN Guang dr...@126.com - Original Message - From: Dan Goodmandg.gm...@thesamovar.net I'm doing some C++ code generation using Python, and would be interested in any comments on the approach I'm taking. PythoidC ( http://pythoidc.googlecode.com ) is a C code generator (not C++) It would be nice if you could start reading the posts before you answer, and then try to give an answer that fits the question. Stefan I have read the post, may be I lost some words and made you misunderstand. I meant: PythoidC ( http://pythoidc.googlecode.com ) is a C code generator (but not C++), if you find it useful, welcome to take a look. -- http://mail.python.org/mailman/listinfo/python-list
Re: C++ code generation
- Original Message - From: Dan Goodmandg.gm...@thesamovar.net I'm doing some C++ code generation using Python, and would be interested in any comments on the approach I'm taking. PythoidC ( http://pythoidc.googlecode.com ) is a C code generator (not C++) It would be nice if you could start reading the posts before you answer, and then try to give an answer that fits the question. Stefan I have read the post, may be I lost some words and made you misunderstand. I meant: PythoidC ( http://pythoidc.googlecode.com ) is a C code generator (but not C++), if you find it useful, welcome to take a look.-- http://mail.python.org/mailman/listinfo/python-list
Re: Python bindings tutorial
Is there any tutorial how to write a bindings for a exe ( dos) program? I would like to run it from a Python directly ( using import command and a particular function from the binding) not using os.system command. An example: PythoidC ( http://pythoidc.googlecode.com ), look at importTemplate.py-- http://mail.python.org/mailman/listinfo/python-list
Re: C++ code generation
PythoidC ( http://pythoidc.googlecode.com ) is a C code generator (not C++) - Original Message - From: Dan Goodman dg.gm...@thesamovar.net To: python-list@python.org Sent: Wednesday, March 17, 2010 9:00 AM Subject: C++ code generation Hi all, I'm doing some C++ code generation using Python, and would be interested in any comments on the approach I'm taking. Basically, the problem involves doing some nested loops and executing relatively simple arithmetic code snippets, like: for i in xrange(len(X)): X[i] += 5 Actually they're considerably more complicated than this, but this gives the basic idea. One way to get C++ code from this would be to use Cython, but there are two problems with doing that. The first problem is that the arithmetic code snippets are user-specified. What I want to do is generate code, and then compile and run it using Scipy's weave package. The second problem is that I have various different data structures and the C++ code generated needs to be different for the different structures (e.g. sparse or dense matrices). So far what I've been doing is writing Python code that writes the C++ code, but in a very non-transparent way. I like the idea of specifying the C++ code using Python syntax, like in Cython. So the idea I came up with was basically to abuse generators and iterators so that when you write something like: for x in X: ... it actually outputs some C++ code that looks like: for(int i=0; iX_len; i++){ double x = X[i]; ... } The ... in the Python code is only executed once because when X is iterated over it only returns one value. Here's the example I've written so far (complete code given below): # initialisation code code = OutputCode() evaluate = Evaluator(code) X = Array(code, 'values') # specification of the C++ loop for x in X: evaluate('x += 5; x *= 2') # and show the output print code.code It generates the following C++ code: for(int values_index=0; values_indexvalues_len; values_index++){ double values = values_array[values_index]; values += 5; values *= 2; } OK, so that's an overview of the idea that I have of how to do it. Any comments or suggestions on either the approach or the implementation? Below is the complete code I've written for the example above (linewraps aren't perfect but there's only a couple of lines to correct). Thanks for any feedback, Dan import re, inspect # We just use this class to identify certain variables class Symbol(str): pass # This class is basically just a mutable string class OutputCode(object): def __init__(self): self.code = '' def __iadd__(self, code): self.code = self.code+code return self # Iterating over instances of this class generates code # for iterating over a C++ array, it yields a single # Symbol object, the variable name of the value in the # array class Array(object): def __init__(self, code, name, dtype='double'): self.name = name self.dtype = dtype self.code = code def __iter__(self): def f(): self.code += 'for(int {name}_index=0; {name}_index{name}_len; {name}_index++){{\n'.format(name=self.name) self.code += '{dtype} {name} = {name}_array[{name}_index];\n'.format(dtype=self.dtype, name=self.name) yield Symbol(self.name) self.code += '}\n' return f() # Instances of this class generate C++ code from Python syntax # code snippets, replacing variable names that are a Symbol in the # namespace with the value of that Symbol. class Evaluator(object): def __init__(self, code): self.code = code def __call__(self, code): # The set of variables in the code snippet vars = re.findall(r'\b(\w+)\b', code) # Extract any names from the namespace of the calling frame frame = inspect.stack()[1][0] globals, locals = frame.f_globals, frame.f_locals values = {} for var in vars: if var in locals: values[var] = locals[var] elif var in globals: values[var] = globals[var] # Replace any variables whose values are Symbols with their values for var, value in values.iteritems(): if isinstance(value, Symbol): code = re.sub(r'\b{var}\b'.format(var=var), str(value), code) # Turn Python snippets into C++ (just a simplified version for now) code = code.replace(';', '\n') lines = [line.strip() for line in code.split('\n')] code = ''.join(line+';\n' for line in lines) self.code += code if __name__=='__main__': code = OutputCode() evaluate = Evaluator(code) X = Array(code, 'values') for x in X: evaluate('x += 5; x *= 2') print code.code -- http://mail.python.org/mailman/listinfo/python-list
RE: python to exe
Does anyone know of a good python to stand alone exe compiler? Thanks, -Robin I tried several such tools and found the easiest one: Pyinstaller ( http://www.pyinstaller.org/ ) but it does not make your script faster, if you want it as fast as C language, please try PythoidC ( http://pythoidc.googlecode.com ) -- http://mail.python.org/mailman/listinfo/python-list
Re: file seek is slow
Metalone wrote: I just tried the seek test with Cython. Cython fseek() : 1.059 seconds. 30% slower than 'C' Python f.seek : 1.458 secondds. 80% slower than 'C'. It is amazing to me that Cython generates a 'C' file that is 1478 lines. PythoidC ( http://pythoidc.googlecode.com ) generates the shortest 'C' file. PythoidC is the C language like the Python, by the Python and for the Python. Except that it's not a language but rather a syntax converter, i.e. it doesn't really add any features to the C language but rather restricts Python syntax to C language features (plus a bit of header file introspection, it seems, but C's preprocessor has a bit of that, too). Stefan PythoidC is a familar language to Python and C programmers, I do not like waste my time to create unfamilar things to waste users' time studying. In fact PythoidC removed some boring features from C language: 1. no semicolon ; at line ends 2. no braces {} , take Pythonic indent region to express code block PythoidC restricts C syntax to Python language feature, so that C language bacomes friendly to Python programmers and Python IDE. PythoidC realized introspection not only on header files but also any C files. The PythoidC introspection will be as good as Python introspection, if only the C header file wirters adds more detailed annotation. PythoidC is a familar and convenient C language tool for Python programmers and mixed programming. plus, PythoidC is realizable only with Python, it's too far beyond C's preprocessor, believe it, or show us. CHEN Guang Convenient C Python mixed programming --- PythoidC ( http://pythoidc.googlecode.com ) -- http://mail.python.org/mailman/listinfo/python-list
Re: file seek is slow
Metalone wrote: I just tried the seek test with Cython. Cython fseek() : 1.059 seconds. 30% slower than 'C' Python f.seek : 1.458 secondds. 80% slower than 'C'. It is amazing to me that Cython generates a 'C' file that is 1478 lines. PythoidC ( http://pythoidc.googlecode.com ) generates the shortest 'C' file. PythoidC is the C language like the Python, by the Python and for the Python. CHEN Guang-- http://mail.python.org/mailman/listinfo/python-list
RE: How to detect C Function block using python
In the source code of PythoidC ( http://pythoidc.googlecode.com ), I wrote a Parser for C header files with Python regular expression, not only functions but also structs macros. May be of some help. Hey All, I'm new in this community. I am writing a static analyzer for validating C Code using python and for that I'm looking for a python module/API that will detect Function block of a given C-File. I know simple function can be detected using push { and poping it if character } is found. This solution is actually done already, I want a robust API that can do more then that like detecting Function name parameters its return types etc. Thanks! Faheem-- http://mail.python.org/mailman/listinfo/python-list
Re: Six Minutes and fourty two seconds
Tobiah wrote: Now that I use python, this is the amount of time per day that I spend adding forgotten semicolons while debugging other languages. What compels you to write Python code without semicolons? Frederic Try the C language without semicolons and braces http://pythoidc.googlecode.com-- http://mail.python.org/mailman/listinfo/python-list
Re: The C language like the Python, by the Python and for the Python--- PythoidC
Dear Stefan, Thanks a lot for your interest in PythoidC. Yes, PythoidC takes regular expression to parse C header files, but there is no danger at all, because, the parsed result is only used for introspecting and auto-completion, has noting to do with syntax converting and compiling. I just improved PythoidC to a satisfying version for me, up to now, all the projects with PythoidC are experimental or educational. PythoidC is mainly used to deal with simple but time consuming tasks in Python project, as you see, PythoidC file can be imported the same any Python files. Oliver ( ChenGuang ) ? CHEN Guang, 08.03.2010 06:08: Hi, if you are interested in C-Python mixed programming, please take a look at: http://pythoidc.googlecode.com PythoidC is the C language like the Python, by the Python and for the Python It looks a bit dangerous to me to parse C header files only with regular expressions. For Cython, some people seem to be using gcc-xml instead, and some have reported that clang is really nice to play with. However, none of those has made its way into Cython yet, mostly due to the dependency it would add. I don't know if tcc (which you seem to depend on) has anything comparable, but I doubt it. Just out of curiosity, is this syntax converter actually used for any real projects? Stefan -- http://mail.python.org/mailman/listinfo/python-list
The C language like the Python, by the Python and for the Python --- PythoidC
Hi, if you are interested in C-Python mixed programming, please take a look at: http://pythoidc.googlecode.com PythoidC is the C language like the Python, by the Python and for the Python import c c.include(c.h.stdio) c.include(c.h.stdlib) '''Annotation is free!''' int fib(int n): if(n=2): return1 else: return fib(n-1)+ fib(n-2) int main(int argc,char**argv): int n //C style annotation n=c.stdlib.atoi(argv[1]) c.stdio.printf('fibonacci(%d)=%d\n', n, fib(n))-- http://mail.python.org/mailman/listinfo/python-list