2to3 ParseError with UTF-8 BOM

2009-11-05 Thread Farshid
ected behavior or a bug in the 2to3 script? -farshid -- http://mail.python.org/mailman/listinfo/python-list

Re: the annoying, verbose self

2007-11-21 Thread Farshid Lashkari
looking at your code in the future. So use it at your own risk! http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/362305 -Farshid -- http://mail.python.org/mailman/listinfo/python-list

Re: Python strings question (vertical stack)

2007-11-20 Thread Farshid Lashkari
J. Clifford Dyer wrote: > I think you mean '\n'.join([string1,string2,string3]) > > You actually do want the \ to do its thing in this case. Yeah, my brain must still be asleep. Thanks for waking it up :) -- http://mail.python.org/mailman/listinfo/python-list

Re: Python strings question (vertical stack)

2007-11-20 Thread Farshid Lashkari
newlines between the strings then you can do the following: String = '\\n'.join([string1,string2,string3]) -Farshid -- http://mail.python.org/mailman/listinfo/python-list

Re: simple? embedding question

2007-10-31 Thread Farshid Lashkari
ing_the_interpreter.html > > btw what kind of object is returned in case i use Py_file_input > in PyRun_String? > Yes, you can keep a reference to maindict if you wish, but make sure you increment the reference count since PyModule_GetDict() returns a borrowed reference. -Farshid -- http://mail.python.org/mailman/listinfo/python-list

Re: simple? embedding question

2007-10-30 Thread Farshid Lashkari
portModuleEx() function. You can use the PyImport_AddModule() function as before, but you must explicitly add the module to the __main__ module. Here is some code: PyObject *mainmod = PyImport_AddModule("__main__"); PyObject *foo = PyImport_ImportModule("foo"); Py_INCREF(foo); //

Re: simple? embedding question

2007-10-30 Thread Farshid Lashkari
t;__main__"); PyObject* maindict = PyModule_GetDict(mainmod); foo = PyImport_ImportModuleEx("foo", maindict , maindict , NULL); bar = PyImport_ImportModuleEx("bar", maindict , maindict , NULL); Once the modules are imported into the __main__ scope, you should be able to use PyRun_SimpleString() to evaluate expressions. -Farshid -- http://mail.python.org/mailman/listinfo/python-list

Re: C API (embedded Python): How to get and set named variables

2007-09-10 Thread Farshid Lashkari
, if you wanted to get the value of an integer in the __main__ module named "foobar", you would do the following: PyObject *m = PyImport_AddModule("__main__"); PyObject *v = PyObject_GetAttrString(m,"foobar"); int foobar = PyInt_AsLong(v); Py_DECREF(v); You will probably

Re: Subclassing zipfile (new style class)

2007-09-06 Thread Farshid Lashkari
t;", line 2, in > TypeError: Error when calling the metaclass bases > module.__init__() takes at most 2 arguments (3 given) In your code 'zipfile' is a module, not a class, so you cannot inherit from it. I believe this is what you are trying to accomplish: class walkZip(zipfile.ZipFile): pass -Farshid -- http://mail.python.org/mailman/listinfo/python-list

Re: Question about embedding python in C++

2007-08-23 Thread Farshid Lashkari
, it would be easier to tell what the problem is. -Farshid -- http://mail.python.org/mailman/listinfo/python-list

Re: Catching SystemExit in C API code when embedding Python?

2007-08-02 Thread Farshid Lashkari
Stefan Bellon wrote: > Thanks for your hints ... > > The interesting part is "Call python code". In my example this is done > with PyRun_SimpleString which does not return if an exception is not > handled but raised "out of" the interpreter. So I am unsure of what you > mean with "Call python code

Re: Catching SystemExit in C API code when embedding Python?

2007-08-02 Thread Farshid Lashkari
Stefan Bellon wrote: > Hi all! > > I am embedding Python into a GUI application in a way that the GUI is > scriptable using Python. > > Now I have come to a problem that when the user puts a "sys.exit(0)" > into his script to end the script, not only the script is terminated, > but also the GUI a

Re: Another C API Question

2007-07-27 Thread Farshid Lashkari
beginner wrote: > I did and it did not seem to work. I ended up doing the following. > Verbose, isn't it? > If I do d=PyFloat_AsDouble(oDiscount); in the third "if", I get an > error. Maybe I missed something obvious. That's strange. I just tried the following code: fprintf(stdout,"True = %lf\n",

Re: Another C API Question

2007-07-27 Thread Farshid Lashkari
beginner wrote: > This works with PyFloat only. It does not work with integers. Did you try it out? I have used it on ints, bools, and objects that implement the __float__ method. It does not work on strings though. -- http://mail.python.org/mailman/listinfo/python-list

Re: Another C API Question

2007-07-26 Thread Farshid Lashkari
beginner wrote: > I know obj is a number, but I do not know the exact type. How can I > convert it to double without writing a giant switch() that exhausts > every single type of number? Try using the PyFloat_AsDouble(...) function, it should be able to convert an object to a double, as long as t

Re: pydoc with METH_VARGS

2007-06-25 Thread Farshid Lashkari
is is what most of Python's built-in functions do. -Farshid -- http://mail.python.org/mailman/listinfo/python-list

Re: EMBEDDING > Run Python & Run C Function

2007-06-22 Thread Farshid Lashkari
tending/embedding python. I believe it does exactly what you want. http://www.python.org/doc/ext/extending-with-embedding.html -Farshid -- http://mail.python.org/mailman/listinfo/python-list

Re: how to convert an integer to a float?

2007-02-27 Thread Farshid Lashkari
Farshid Lashkari wrote: > When two integers are involved in a division, the result will also be a > division. My bad, I meant the result will also be an *integer* -Farshid -- http://mail.python.org/mailman/listinfo/python-list

Re: how to convert an integer to a float?

2007-02-27 Thread Farshid Lashkari
one of the operands is a float, then the result will be a float instead. So try casting one of the values to a float before performing the division: dx = float(abs(i2 - i1))/min(i2, i1) -Farshid -- http://mail.python.org/mailman/listinfo/python-list

Re: f---ing typechecking

2007-02-14 Thread Farshid Lashkari
t;>> L = [1] >>> L += (2,) >>> L [1, 2] It seems like the '+' operator for lists should accept any iterable for the right side argument to be consistent with extend() and the '+=' operator. -Farshid -- http://mail.python.org/mailman/listinfo/python-list

Re: sending string or list to a function

2006-12-04 Thread Farshid Lashkari
27;t consider it bad programming style to allow your functions to accept multiple data types. def MyFunction(val): if isinstance(val,basestring): val = [val] for s in val: #Process string -Farshid -- http://mail.python.org/mailman/listinfo/python-list

Re: Multithreaded C API Python questions

2006-11-09 Thread Farshid Lashkari
g call at the beginning of your application: PyEval_InitThreads() From my experience, calling PyGILState_Ensure() was enough. I didn't need to call any extra threading functions. But make sure that every call to PyGILState_Ensure() is matched with a call to PyGILState_Release() -Far

Re: is this the right way to do subclasses?

2006-11-08 Thread Farshid Lashkari
kw): Character.__init__(self, *args, **kw) self.health += 2 self.strength += 1 This way, if you add a new parameter to the base class, you won't need to update all the derived classes. -Farshid -- http://mail.python.org/mailman/listinfo/python-list

Re: C wrapper

2006-11-07 Thread Farshid Lashkari
for creating extension modules, especially the following page: http://docs.python.org/ext/methodTable.html "The initialization function must be named initname(), where name is the name of the module, and should be the only non-static item defined in the module file" -Farshid -- http:

Re: Hooking file open

2006-11-01 Thread Farshid Lashkari
aced the logging after the call to the real function so that files that don't exist will not be logged. However, I'm already checking for file existence during the post process of the script running, so I guess it doesn't really make too much of a difference. Thanks for the help.

Hooking file open

2006-11-01 Thread Farshid Lashkari
will still fall through my checks, especially file opens from C extensions, which is fine. I just want to be able to detect the most common use cases. Any other suggestions are appreciated. -Farshid -- http://mail.python.org/mailman/listinfo/python-list

Re: What is the cleanest way to for a module to access objects from the script that imports it?

2006-10-27 Thread Farshid Lashkari
odule using the following syntax: reload(mymodule) -Farshid -- http://mail.python.org/mailman/listinfo/python-list

Re: cleaner way to write this?

2006-10-25 Thread Farshid Lashkari
D_OK: > db_name = dlg.GetValue() > dlg.Destroy() > return db_name > > but I suppose it's a matter of preference. Yeah, I think the second way is usually used by people who are more accustomed to programming in C, since they need to initialize variables. Yo

Re: cleaner way to write this?

2006-10-25 Thread Farshid Lashkari
s should work: def create_db_name(self): dlg = wx.TextEntryDialog(self.frame, 'Enter a database name:', 'Create New Database') db_name = None if dlg.ShowModal() == wx.ID_OK: db_name = dlg.GetValue() dlg.Destroy() return db_name -Farshid -- http://mail.python.org/mailman/listinfo/python-list

Re: return tuple from C to python (extending python)

2006-10-24 Thread Farshid Lashkari
do something like Py_BuildValue("i", 123), but see > http://docs.python.org/ext/buildValue.html for more info. Simon is correct. You need to create a python object from your unsigned int. Try the following instead: PyTuple_SET_ITEM(toRet, i, PyInt_FromLong(dat[i]) ); -Farshid -- http://m

Re: storing variable names in a list before they are used?

2006-09-29 Thread Farshid Lashkari
get.get_text() print first_name If you want these variables to be assigned to an object then you can use setattr(): name = 'first_name' setattr(obj,name,widget.get_text()) print obj.first_name Hope this helps -Farshid -- http://mail.python.org/mailman/listinfo/python-list

Releasing GIL in unknown state

2006-08-29 Thread Farshid Lashkari
t the GIL is already acquired. All I can think of so far is the following: PyGILState_STATE state = PyGILState_Ensure(); Py_BEGIN_ALLOW_THREADS //do processing Py_END_ALLOW_THREADS PyGILState_Release(state) Is there a better way? -Farshid -- http://mail.python.org/mailman/listinfo/python-list

Re: Inheritting Built In Types

2006-08-16 Thread Farshid Lashkari
Digital Logic wrote: > Am I checking for the slice object incorrectly? That's the only thing > I can think of. Yes. The slice object is the "i" variable in your code, not the "data" variable. -Farshid -- http://mail.python.org/mailman/listinfo/python-list

Re: error handling

2006-08-10 Thread Farshid Lashkari
e OP said he wanted to print out that error message whenever the interpreter came across any IndexError. So I gave him what he wanted. I guess he needs to be more careful what he wishes for ;) -Farshid -- http://mail.python.org/mailman/listinfo/python-list

Re: error handling

2006-08-10 Thread Farshid Lashkari
; before it exits? Hi, Try placing the try/except block around the main function of your program: if __name__ == '__main__': try: main() except IndexError: sys.exit("That number is way too big!") -Farshid -- http://mail.python.org/mailman/listinfo/python-list

Re: loop until keypress (Windows XP)

2006-08-09 Thread Farshid Lashkari
r = msvcrt.getch() Keep in mind that this will only work on windows. -Farshid -- http://mail.python.org/mailman/listinfo/python-list

Re: Newbie question: what's with "self"?

2006-08-08 Thread Farshid Lashkari
ling "self"s in all over > the place to see if that helps, but without much of an idea of what it > really achieves. > > Thanks in advance!! > Hi, Take a look at the following FAQ on the python homepage: http://www.python.org/infogami-faq/general/why-must-self-be-us

Re: Missing MSVCR71.dll

2006-08-08 Thread Farshid Lashkari
it worked fine. -Farshid -- http://mail.python.org/mailman/listinfo/python-list

Re: singleton decorator

2006-08-07 Thread Farshid Lashkari
it might not be in the current version of python. -Farshid -- http://mail.python.org/mailman/listinfo/python-list

Re: Calling python functions from C

2006-05-09 Thread Farshid Lashkari
mbedding.html -Farshid -- http://mail.python.org/mailman/listinfo/python-list

Re: can someone explain why ..

2006-04-25 Thread Farshid Lashkari
l also become garbage collected at the end of the constructor. Are you sure this is the case? -Farshid -- http://mail.python.org/mailman/listinfo/python-list

Re: can someone explain why ..

2006-04-25 Thread Farshid Lashkari
t seems as thought with 2, the "image" variable is garbage collected after the constructor of Main is called. With 1, you save a reference to the image, so it does not get garbage collected. -Farshid -- http://mail.python.org/mailman/listinfo/python-list

Re: python to c API, passing a tuple array

2006-04-14 Thread Farshid Lashkari
tuple = PyTuple_GetItem(args,i); if(!PyArg_ParseTuple(tuple,"sff",...) { //handle error Py_RETURN_NONE; } } } Also, you need to INCREF Py_None before you return it. Or you can use the macro used in the sample code above. -Farshid -- http://mail.python.org/mailman/listinfo/python-list

Re: From Python to c++

2006-03-21 Thread Farshid Lashkari
t; Since you know the type, you would use boost::any_cast to convert it to that type. You can find information about it here: http://www.boost.org/doc/html/any.html -Farshid -- http://mail.python.org/mailman/listinfo/python-list

Re: Passing a method indirectly

2006-03-04 Thread Farshid Lashkari
You don't need to pass the object along with the method. The method is bound to the object. Simply call the method by itself: def ObjApply(method): method() class Test: def test1 (self): print "Hello" def test2 (self): ObjApply(self.test1) ta = Test () ta

Re: when do two names cease to refer to the same string object?

2006-03-02 Thread Farshid Lashkari
I asked a similar question a few weeks ago. I think the answers I got will also answer your question as well. Here's a link to the thread: http://groups.google.com/group/comp.lang.python/browse_thread/thread/2f6f1d399ba94a7b/f564a219ffe44149?lnk=st&rnum=1&hl=en#f564a219ffe44

Re: file.read problem

2006-02-17 Thread Farshid Lashkari
e in 'rbU' mode. This will use universal newline mode and convert all carriage returns to line feeds. -Farshid -- http://mail.python.org/mailman/listinfo/python-list

Re: file.read problem

2006-02-17 Thread Farshid Lashkari
> I am working on a script to get parts of raw data out of a file, and > the data I read has to be the data written in the file without CR or > LF. So you just want to remove all the linefeeds? This should work then: data = data.replace('\n','') -Farshid -- h

Re: Is empty string cached?

2006-02-16 Thread Farshid Lashkari
just being curious :) -Farshid -- http://mail.python.org/mailman/listinfo/python-list

Re: Is empty string cached?

2006-02-15 Thread Farshid Lashkari
> It just boils down to either a LOAD_CONST vs. a LOAD_NAME - either way > the string isn't duplicated. Great, that's exactly what I wanted to know. Thanks Steve! -Farshid -- http://mail.python.org/mailman/listinfo/python-list

Re: Is empty string cached?

2006-02-15 Thread Farshid Lashkari
stated, is it not important at all? Thanks, Farshid -- http://mail.python.org/mailman/listinfo/python-list

Re: Is empty string cached?

2006-02-15 Thread Farshid Lashkari
't understand the point of your last expression. Were you intending this instead: >>> c is a True However, the following commands add to my confusion: >> a = 'wtf?' >> b = 'wtf?' >> a is b False So how are string literals ca

Re: How to import a module with spaces in the name

2006-02-15 Thread Farshid Lashkari
Gregory PiƱero wrote: > Let's say I have a module named "Excellent Module.py" ExcellentModule = __import__('Excellent Module') -Farshid -- http://mail.python.org/mailman/listinfo/python-list

Is empty string cached?

2006-02-15 Thread Farshid Lashkari
This leads me to believe that python does reuse existing strings, but once the variables are removed, does the item still exist in the cache? -Farshid -- http://mail.python.org/mailman/listinfo/python-list

Re: python spawn new process, rout stdin/out

2006-02-09 Thread Farshid Lashkari
Sounds like the popen2 module should suffice. Take a look at the documentation for the module here: http://www.python.org/doc/lib/module-popen2.html -Farshid -- http://mail.python.org/mailman/listinfo/python-list

Re: translating PHP to Python

2006-02-05 Thread Farshid Lashkari
hon to say "You, Parent > Object, do ...stuff!" Use the super() function to access an attribute of a parent clas class C(B): def meth(self, arg): super(C, self).meth(arg) -Farshid -- http://mail.python.org/mailman/listinfo/python-list

Re: Embedding Python into C/C++ applications

2006-02-03 Thread Farshid Lashkari
f example? Here is a link to a two part tutorial on Code Project that might help you out: http://www.codeproject.com/cpp/embedpython_1.asp http://www.codeproject.com/cpp/embedpython_2.asp -Farshid -- http://mail.python.org/mailman/listinfo/python-list

Re: would it be feasable to write python DJing software

2006-02-02 Thread Farshid Lashkari
f my fscking mind? > What do you mean by DJing? Queueing and playing audio files? If so, python should work fine. Check out the PyMedia library for playing/mixing audio with python. -Farshid -- http://mail.python.org/mailman/listinfo/python-list

Re: calling a class method in a python module

2006-02-01 Thread Farshid Lashkari
result) { //Do something with result Py_DECREF(result); } Py_DECREF(func); } Have a look in the "Python/C API Reference Manual" for more information. -Farshid -- http://mail.python.org/mailman/listinfo/python-list

Re: Having Trouble with Scoping Rules

2006-01-30 Thread Farshid Lashkari
(): global _expensiveObject if not(_expensiveObject): _expensiveObject = "A VERY Expensive object" return _expensiveObject The documentation will no doubtedly explain it better than I have -Farshid -- http://mail.python.org/mailman/listinfo/python-list

Re: A class with eventhandlers ?

2006-01-29 Thread Farshid Lashkari
It's definitely possible, here's a small example. There are probably better ways to do it, but I'll let you figure that out ;) class ErrorHandler: def __init__(self,method): self.method = method self.errorHook = None def onError(sel

Re: generating method names 'dynamically'

2006-01-26 Thread Farshid Lashkari
hod name. Here's a simple example: class MyClass: def DummyMethodName(self): pass setattr(MyClass,'NewMethodName',MyClass.DummyMethodName) -Farshid -- http://mail.python.org/mailman/listinfo/python-list

Re: exporting multiple modules from one dll?

2006-01-26 Thread Farshid Lashkari
video import input I've never actually tried this, but I don't see why it wouldn't work. Let me know how it goes. -Farshid -- http://mail.python.org/mailman/listinfo/python-list

Re: Executing script with embedded python

2006-01-25 Thread Farshid Lashkari
ss, or NULL on failure". So it seems like the call is failing. My guess would be that modules are not callable objects. Also, this seems somewhat redundant since your module is effectively executed when you import it using the PyImport_Import function. -Farshid -- http://mail.python.o

Re: C Extended module init/cleanup

2006-01-23 Thread Farshid Lashkari
exits. Here is a sample code snippet: //Called when python exits void CleanupModule(void) { //Perform cleanup here } Then in your init function add the following code: //Register function to be called when python exits Py_AtExit(CleanupModule); -Farshid -- http://mail.python.org/mailman

Re: Problems with import of modules

2006-01-23 Thread Farshid Lashkari
> How can I modify the python search-path from within the script, thus it > contains the doc directory? Hi, The sys.path variable is a list of strings that contains the current module search path. You can add your own path to this list: import sys sys.path.append('../') -

Re: Redirecting standard out in a single namespace

2006-01-20 Thread Farshid Lashkari
s of namespace namespace.sys = mysys This seems like it should work, however I don't know if copying the entire dictionary of one module to another is a safe thing to do. -Farshid -- http://mail.python.org/mailman/listinfo/python-list

Re: Determine if object is a Bound or Unbound method

2005-07-28 Thread Farshid Lashkari
Grazie! Paolino wrote: > Farshid Lashkari wrote: > >> Hi, >> >> I have an object and I want to check if it is a bound or unbound >> method, or neither. I tried using the types module, but it seems as >> though types.UnboundMethodType and types.MethodType are

Determine if object is a Bound or Unbound method

2005-07-28 Thread Farshid Lashkari
Hi, I have an object and I want to check if it is a bound or unbound method, or neither. I tried using the types module, but it seems as though types.UnboundMethodType and types.MethodType are equal. How else can I determine this? BTW, I'm using Python 2.3 Thanks, Farshid --

Re: How to find the classname of an object? (was Python Documentation)

2005-05-12 Thread Farshid Lashkari
This will get the name of an objects class obj.__class__.__name__ This will return a tuple of its base classes obj.__class__.__bases__ Christopher J. Bottaro wrote: > I actually want all the parent classes too. So if D derives off C derives > off B derives off A, I ultimately want a tuple ('D'