Re: Need an identity operator because lambda is too slow
On Sat, 17 Feb 2007 22:19:41 -0800, Raymond Hettinger wrote: > [Deron Meranda >>] I'm looking for something in >> Python which would act like an identity operator, or I-combinator: a >> do-nothing function. The best I know of is: (lambda x: x), but it is >> not ideal. > > File a feature request on SourceForge and assign to me. This has come > up a couple of times and would be trivial to implement in the operator > or functools modules. I'm surprised. The Original Poster specified [quote] What python needs is something like a built-in "operator.identity" function, which acts like "lambda x:x", but which the byte compiler could recognize and completely optimize away so there is no function call overhead. [end quote] I would have guessed that optimizing the call away would require support from the compiler. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list
Re: Getting a class name
En Sun, 18 Feb 2007 04:20:33 -0300, goodwolf <[EMAIL PROTECTED]> escribió: > I suppose that you wont get class name into its code (or before > definition end) but not into a method definition. > > > import sys > > def getCodeName(deap=0): > return sys._getframe(deap+1).f_code.co_name > > > class MyClass (object): > name = getCodeName() + '!' What's the advantage over MyClass.__name__? -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: cmd all commands method?
On Feb 17, 11:44 pm, Bjoern Schliessmann wrote: > placid wrote: > > if i want to treat every cmdloop prompt entry as a potential > > command then i need to overwrite the default() method ? > > Excuse me, what's a cmdloop prompt? What's the "default() method"? > > > What i want to achieve is to be able to support global variable > > creation for example; > > > res = sum 1 2 > > > this would create a variable res with the result of the method > > do_sum() ? > > > then would i be able to run; > > > sum a 5 > > > this would return 8 or an error saying that res is not defined > > Are you sure you're talking about Python here? Yes, he is talking about the cmd module: http://docs.python.org/dev/lib/Cmd-objects.html. However that module was never intended as a real interpreter, so defining variables as the OP wants would require some work. Michele Simionato -- http://mail.python.org/mailman/listinfo/python-list
Re: conver string to dictionary
En Sun, 18 Feb 2007 03:44:47 -0300, mahdieh saeed <[EMAIL PROTECTED]>
escribió:
> Hi
> I want to convert string to dictionary .what is the best solution for
> this ?
> for example string is like this:
>
> '{"SalutationID":["primarykey",8388607,0,None],"CompanyID":[0,8388607,0,"index"],
> "SalutationName":["",255,0,None],"isDefault":["tinyint",1,1,None]}'
> and I want to convert this string to this dictionary:
>
> {"SalutationID":["primarykey",8388607,0,None],"CompanyID":[0,8388607,0,"index"],
> "SalutationName":["",255,0,None],"isDefault":["tinyint",1,1,None]}
> please help me what is the best solution(faster solution) for this?
The simplest way is to use eval(), but only do that if you can trust
absolutely the source. To be safe, you can use this recipe:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/364469
--
Gabriel Genellina
--
http://mail.python.org/mailman/listinfo/python-list
Re: conver string to dictionary
> I want to convert string to dictionary .what is the best solution for this?
> for example string is like this:
>
>
> '{"SalutationID":["primarykey",8388607,0,None],"CompanyID":[0,8388607,0,"index"],
> "SalutationName":["",255,0,None],"isDefault":["tinyint",1,1,None]}'
>
> and I want to convert this string to this dictionary:
>
>
> {"SalutationID":["primarykey",8388607,0,None],"CompanyID":[0,8388607,0,"index"],
> "SalutationName":["",255,0,None],"isDefault":["tinyint",1,1,None]}
>
> please help me what is the best solution(faster solution) for this?
If you have simplejson ( http://cheeseshop.python.org/pypi/simplejson
) installed you can do
mydict = simplejson.loads( mystring )
but in this case all occurances of 'None' in your string should be 'null'.
Or if you absolutely trust the string to contain nothing dangerous:
exec( 'mydict = %s' % mystring )
HTH,
Daniel
--
http://mail.python.org/mailman/listinfo/python-list
Extracurricular Activities at PyCon This Year
At PyCon this year we are having a significant number of activities besides the keynotes and talks. One group of those are the birds-of-a-feather gatherings being held in the evenings. The Python community consists of a number of smaller communities and we're encouraging them to hold meetings, dinners and other activities at PyCon this year. The organizers have tried to leave room in the busy schedule for these to happen and of course for some non-Python social BoFs as well. Here are the BoFs with which you have the opportunity to get involved: * Python in Education * Python in Science * Healthcare and Python * A Content Repository Standard for Python * Jython Development * Django * Pylons Web Framework * Trac Users and Developers * Keysigning Party * Tech that Runs the Python Conference * Users of Bazaar Version Control/Launchpad * Buildbot Users and Developers * Python Advocacy Community Forum * Texas Regional Unconference Dinner Meet * PyGame Programming/Playing Clinic * Board Game Socials * Bowling * Climbers You can check them out at: http://us.pycon.org/TX2007/BoF The room/offsite schedule is listed at the bottom of that page but many of the groups have not yet declared when and where they are meeting. Nudges are welcome. The other set of activities at PyCon are the 4-days of code sprints held at the end of the conference. A sprint is a focused development session, in which developers gather in a room and focus on building a particular subsystem. A sprint is organized with a coach leading the session. The coach sets the agenda, tracks activities, and keeps the development moving. The developers will sometimes work in pairs using the Extreme Programming (XP) pair programming approach. The sprints that have announced so far are: * Work towards Zope 3.4 release * Fun Educational Software for "Playful Learning" * PyCon-Tech: Improve the convention software * Zope 3 Learner's Circle * Python Job Board * Django * Trac * Jython * Docutils: squash bugs & add features * TurboGears * Write a Game * Create a Win32 version of MySQLdb under Python 2.5 * SchoolTool & CanDo Sprint coaches should plan for an introductory session on Sunday afternoon or Monday morning, to help attendees get started. This might involve helping them to get SVN or CVS installed and checking out the development tree, talking about the software's architecture, or planning what the four-day sprint will try to accomplish. You can read more at: http://us.pycon.org/TX2007/Sprinting and even add your name to particular sprint wiki pages, to encourage them to happen. See you later this week. Get plenty of sleep beforehand, you won't get much at PyCon this year! Jeff Rush PyCon Co-Chair -- http://mail.python.org/mailman/listinfo/python-list
Re: Complex HTML forms
George Sakkis schrieb:
> I'd like to gather advice and links to any existing solutions (e.g.
> libraries, frameworks, design patterns) on general ways of writing
> complex web forms, as opposed to the typical {name:value} flat model.
> A particular case of what I mean by complex is hierarchical forms. For
http://toscawidgets.org/
http://docs.turbogears.org/1.0/SimpleWidgetForm
--
Greg
--
http://mail.python.org/mailman/listinfo/python-list
Re: cmd all commands method?
On Feb 18, 7:17 pm, "Michele Simionato" <[EMAIL PROTECTED]> wrote: > On Feb 17, 11:44 pm, Bjoern Schliessmann > > > [EMAIL PROTECTED]> wrote: > > placid wrote: > > > if i want to treat every cmdloop prompt entry as a potential > > > command then i need to overwrite the default() method ? > > > Excuse me, what's a cmdloop prompt? What's the "default() method"? > > > > What i want to achieve is to be able to support global variable > > > creation for example; > > > > res = sum 1 2 > > > > this would create a variable res with the result of the method > > > do_sum() ? > > > > then would i be able to run; > > > > sum a 5 > > > > this would return 8 or an error saying that res is not defined > > > Are you sure you're talking about Python here? > > Yes, he is talking about the cmd > module:http://docs.python.org/dev/lib/Cmd-objects.html. > However that module was never intended as a real interpreter, so > defining variables > as the OP wants would require some work. > > Michele Simionato How much work does it require ? -- http://mail.python.org/mailman/listinfo/python-list
Re: PyDev on Mac
Ahmer schrieb: > I've been trying to set up PyDev on my new MacBook Pro, but i have not > had an success. > > Could you please help! Just wait until my crystal ball comes back from the cleaners, and I will start looking at your problem. As you can lay back and do nothing while that happens, I suggest you take this highly entertaining read: http://www.catb.org/~esr/faqs/smart-questions.html Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: cmd all commands method?
placid wrote:
> On Feb 18, 7:17 pm, "Michele Simionato" <[EMAIL PROTECTED]>
> wrote:
>> On Feb 17, 11:44 pm, Bjoern Schliessmann >
>>
>>
>> [EMAIL PROTECTED]> wrote:
>> > placid wrote:
>> > > if i want to treat every cmdloop prompt entry as a potential
>> > > command then i need to overwrite the default() method ?
>>
>> > Excuse me, what's a cmdloop prompt? What's the "default() method"?
>>
>> > > What i want to achieve is to be able to support global variable
>> > > creation for example;
>>
>> > > res = sum 1 2
>>
>> > > this would create a variable res with the result of the method
>> > > do_sum() ?
>>
>> > > then would i be able to run;
>>
>> > > sum a 5
>>
>> > > this would return 8 or an error saying that res is not defined
>>
>> > Are you sure you're talking about Python here?
>>
>> Yes, he is talking about the cmd
>> module:http://docs.python.org/dev/lib/Cmd-objects.html. However that
>> module was never intended as a real interpreter, so defining variables
>> as the OP wants would require some work.
>>
>> Michele Simionato
>
> How much work does it require ?
Too much. However, here's how far I got:
import cmd
import shlex
DEFAULT_TARGET = "_"
def number(arg):
for convert in int, float:
try:
return convert(arg)
except ValueError:
pass
return arg
class MyCmd(cmd.Cmd):
def __init__(self, *args, **kw):
cmd.Cmd.__init__(self, *args, **kw)
self.namespace = {}
self.target = DEFAULT_TARGET
def precmd(self, line):
parts = line.split(None, 2)
if len(parts) == 3 and parts[1] == "=":
self.target = parts[0]
return parts[2]
self.target = DEFAULT_TARGET
return line
def resolve(self, arg):
args = shlex.split(arg)
result = []
for arg in args:
try:
value = self.namespace[arg]
except KeyError:
value = number(arg)
result.append(value)
return result
def calc(self, func, arg):
try:
result = self.namespace[self.target] = func(self.resolve(arg))
except Exception, e:
print e
else:
print result
def do_sum(self, arg):
self.calc(sum, arg)
def do_max(self, arg):
self.calc(max, arg)
def do_print(self, arg):
print " ".join(str(arg) for arg in self.resolve(arg))
def do_values(self, arg):
pairs = sorted(self.namespace.iteritems())
print "\n".join("%s = %s" % nv for nv in pairs)
def do_EOF(self, arg):
return True
if __name__ == "__main__":
c = MyCmd()
c.cmdloop()
Peter
--
http://mail.python.org/mailman/listinfo/python-list
Re: cmd all commands method?
On Feb 18, 10:49 am, "placid" <[EMAIL PROTECTED]> wrote: > On Feb 18, 7:17 pm, "Michele Simionato" <[EMAIL PROTECTED]> > > > Yes, he is talking about the cmd > > module:http://docs.python.org/dev/lib/Cmd-objects.html. > > However that module was never intended as a real interpreter, so > > defining variables > > as the OP wants would require some work. > > > Michele Simionato > > How much work does it require ? Have you ever written an interpreter? It is a nontrivial job. Michele Simionato -- http://mail.python.org/mailman/listinfo/python-list
string.find returns -1 when string evidently in source file
hi,
the following is returning -1:
import string
import sys
x = open("latvian.txt",'r')
x1 = x.read()
print x1.find("LAYOUT")
---
given a file like this
KBD Layout01"Latvian (QWERTY) (Custom)"
COPYRIGHT "(c) 2007 IG"
COMPANY "IG"
LOCALEID"0426"
VERSION 1.0
SHIFTSTATE
0 //Column 4
1 //Column 5 : Shft
2 //Column 6 : Ctrl
6 //Column 7 : Ctrl Alt
7 //Column 8 : Shft Ctrl Alt
LAYOUT ;an extra '@' at the end is a dead key
//SCVK_ Cap 0 1 2 6 7
//--
02 1 0 1 0021-1 00a0-1
// DIGIT ONE, EXCLAMATION MARK, ,
NO-BREAK SPACE,
03 2 0 2 0040-1 00ab-1
// DIGIT TWO, COMMERCIAL AT, ,
LEFT-POINTING DOUBLE ANGLE QUOTATION MARK *,
04 3 0 3 0023-1 00bb-1
// DIGIT THREE, NUMBER SIGN, ,
RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK *,
05 4 0 4 0024-1 20ac00a7
// DIGIT FOUR, DOLLAR SIGN, , EURO
SIGN, SECTION SIGN
06 5 0 5 0025-1 -1 00b0
// DIGIT FIVE, PERCENT SIGN, ,
, DEGREE SIGN
07 6 0 6 005e-1 2019-1
// DIGIT SIX, CIRCUMFLEX ACCENT, ,
RIGHT SINGLE QUOTATION MARK,
08 7 0 7 0026-1 -1 00b1
// DIGIT SEVEN, AMPERSAND, , ,
PLUS-MINUS SIGN
09 8 0 8 002a-1 -1 00d7
// DIGIT EIGHT, ASTERISK, , ,
MULTIPLICATION SIGN
0a 9 0 9 0028-1 -1 -1
// DIGIT NINE, LEFT PARENTHESIS, , ,
0b 0 0 0 0029-1 -1 -1
// DIGIT ZERO, RIGHT PARENTHESIS, ,
,
0c OEM_MINUS 0 002d005f-1 20132014
// HYPHEN-MINUS, LOW LINE,
, EN DASH, EM DASH
0d OEM_PLUS0 003d002b-1 -1 -1
// EQUALS SIGN, PLUS SIGN, ,
,
10 Q 1 q Q -1 -1 -1
// LATIN SMALL LETTER Q, LATIN CAPITAL LETTER Q,
, ,
11 W 1 w W -1 -1 -1
// LATIN SMALL LETTER W, LATIN CAPITAL LETTER W,
, ,
12 E 1 e E -1 01130112
// LATIN SMALL LETTER E, LATIN CAPITAL
LETTER E, , LATIN SMALL LETTER E WITH MACRON, LATIN CAPITAL
LETTER E WITH MACRON
13 R 1 r R -1 01570156
// LATIN SMALL LETTER R, LATIN CAPITAL
LETTER R, , LATIN SMALL LETTER R WITH CEDILLA, LATIN CAPITAL
LETTER R WITH CEDILLA
14 T 1 t T -1 -1 -1
// LATIN SMALL LETTER T, LATIN CAPITAL LETTER T,
, ,
15 Y 1 y Y -1 -1 -1
// LATIN SMALL LETTER Y, LATIN CAPITAL LETTER Y,
, ,
16 U 1 u U -1 016b016a
// LATIN SMALL LETTER U, LATIN CAPITAL
LETTER U, , LATIN SMALL LETTER U WITH MACRON, LATIN CAPITAL
LETTER U WITH MACRON
17 I 1 i I -1 012b012a
// LATIN SMALL LETTER I, LATIN CAPITAL
LETTER I, , LATIN SMALL LETTER I WITH MACRON, LATIN CAPITAL
LETTER I WITH MACRON
18 O 1 o O -1 00f500d5
// LATIN SMALL LETTER O, LATIN CAPITAL
LETTER O, , LATIN SMALL LETTER O WITH TILDE, LATIN CAPITAL
LETTER O WITH TILDE
19 P 1 p P -1 -1 -1
// LATIN SMALL LETTER P, LATIN CAPITAL LETTER P,
, ,
1a OEM_4 0 005b007b-1 -1 -1
// LEFT SQUARE BRACKET, LEFT CURLY
BRACKET, , ,
1b OEM_6 0 005d007d-1 -1 -1
// RIGHT SQUARE BRACKET, RIGHT CURLY
BRACKET, , ,
1e A 1 a A -1 01010100
// LATIN SMALL LETTER A, LATIN CAPITAL
LETTER A, , LATIN SMALL LETTER A WITH MACRON, LATIN CAPITAL
LETTER A WITH MACRON
1f S 1 s S -1 01610160
// LATIN SMALL LETTER S, LATIN CAPITAL
LETTER S, , LATIN SMALL LETTER S WITH CARON, LATIN CAPITAL
LETTER S WITH CARON
20 D 1 d D -1 -1 -1
// LATIN SMALL LETTER D, LATIN CAPITAL LETTER D,
, ,
21 F 1 f F -1 -1 -1
// LATIN SMALL LETTER F, LATIN CAPITAL LETTER F,
, ,
22 G 1 g G -1 01230122
// LATIN SMALL LETTER G, LATIN CAPITAL
LETTER G, , LATIN S
Re: conver string to dictionary
On Feb 18, 2007, at 12:44 AM, mahdieh saeed wrote:
I want to convert string to dictionary .what is the best solution
for this ?
for example string is like this:
'{"SalutationID":["primarykey",8388607,0,None],"CompanyID":
[0,8388607,0,"index"],
"SalutationName":["",255,0,None],"isDefault":["tinyint",1,1,None]}'
and I want to convert this string to this dictionary:
{"SalutationID":["primarykey",8388607,0,None],"CompanyID":
[0,8388607,0,"index"],
"SalutationName":["",255,0,None],"isDefault":["tinyint",1,1,None]}
# you're the one building the string?
a = eval('{"SalutationID":["primarykey",8388607,0,None],"CompanyID":
[0,8388607,0,"index"],
"SalutationName":["",255,0,None],"isDefault":["tinyint",1,1,None]}')
---
A clever person solves a problem.
A wise person avoids it.
-Albert Einstein
--
http://mail.python.org/mailman/listinfo/python-list
Re: basic jython question
> On Feb 15, 1:53 pm, "Richard Brodie" <[EMAIL PROTECTED]> wrote: > > Since the CPython module is heavily influenced by the native Javalogging > > framework (and/or log4j), I would have thought that it would be easier > > to create a Jython wrapper for those. Agreed, but if you copy the logging folder from the CPython Lib folder to the jython lib folder, it should work (except for use of other modules which wouldn't perhaps be available under Java, such as syslog, win32 etc.) - so files, console streams etc. should be OK. Clearly, a facade over an existing system such as log4j or java.util.logging would have the potential to perform better. Regards, Vinay Sajip -- http://mail.python.org/mailman/listinfo/python-list
Dlls
Hi. I am interested to know why python can't access DLL files directly. It seems to me that because python can't access DLL's directly we have to waste our time and write wrappers around libraries that have already been written. So if the python developers were to implement say this. import MYDLL.dll Then we would be able to do everything with that library that we can do in other languages. For eg. I want to use PyOpenGL. But the problem is the library hasn't got all the opengl functions implemented. So I can either develop quickly with an incomplete library or develop slowly in assembler. I mean really, in asm we just call the dll function directly. Why must python be different? -- http://mail.python.org/mailman/listinfo/python-list
Re: Need an identity operator because lambda is too slow
On Feb 18, 5:59 am, "Deron Meranda" <[EMAIL PROTECTED]> wrote: > Consider a much-simplified example of such an iteration where > sometimes you need to transform an item by some function, but most of > the time you don't: > > if some_rare_condition: > func = some_transform_function > else: > func = lambda x: x > for item in some_sequence: > item2 = func(item) > . # more stuff > > Now the "lambda x:x" acts suitably like an identity operator. But it > is very slow, when compared to using more complex-looking code: > > do_transform = some_rare_condition > for item in some_sequence: > if do_transform: > item2 = transform_function(item) > else: > item2 = item > . # more stuff > > What python needs is something like a built-in "operator.identity" > function, which acts like "lambda x:x", but which the byte compiler > could recognize and completely optimize away so there is no function > call overhead. Unless I'm misunderstanding you, you seem to be proposing that the compiler should avoid generating the call to func2() if it has a certain value. How could that information possibly be available at compile time? -- David -- http://mail.python.org/mailman/listinfo/python-list
Re: Getting a class name
On Feb 17, 8:33 pm, deelan <[EMAIL PROTECTED]> wrote: > Harlin Seritt wrote: > > Hi, > > > How does one get the name of a class from within the class code? I > > tried something like this as a guess: > > > self.__name__ > > Get the class first, then inspect its name: > > >>> class Foo(object): pass > ... > >>> f = Foo() > >>> f.__class__.__name__ > 'Foo' > >>> > Why is the __name__ attribute not available to the instance? Why don't normal lookup rules apply (meaning that a magic attribute will be looked up on the class for instances) ? Fuzzyman http://www.voidspace.org.uk/python/articles.shtml > HTH > > -- > d. -- http://mail.python.org/mailman/listinfo/python-list
Distutils: Python version information
In Python cheese shop, there is a field that shows the Python version that is required by a listed package. I have not found this covered in the distutils documentation: How do you add the Python version information into the setup script of a package? Unfortunately, the keyword list: http://docs.python.org/dist/meta-data.html is incomplete (for example, the "provides" and "requires" keywords are not listed, even though covered in the previous chapters of the documentation). -Samuel -- http://mail.python.org/mailman/listinfo/python-list
Re: Help Required for Choosing Programming Language
Stef Mientki wrote: > Some examples: > - Creating a treeview (like in the M$ explorer), with full edit > capabilities and full drag & drop facilities: Delphi takes about > 40 lines of code (most of them even ^C ^V). - Creating a graphical > overview of relations between database tables, which can be > graphical manipulated by the user (like in M$ Access): Delphi 20 > lines of code. I wonder what this costs in Python ? My Chrysler 300C SRT8 takes someVeryLowNumber seconds to accelerate to 100 mph. I wonder how long this takes with a BMW? > I would love to see: > - a comparison between wx and gtk Best would be to try the introduction tutorials yourself. Also be aware that wxWidgets and GTK are C/C++ libraries and wxPython and wxGTK are "just" Python bindings with a few enhancements for it. > (QT doesn't have a very inviting license ;-) GNU GPL isn't inviting? Regards, Björn -- BOFH excuse #352: The cables are not the same length. -- http://mail.python.org/mailman/listinfo/python-list
Re: How do I save the contents of a text buffer
Solved!
# Output file
outfile = open("newbannedsitelist", "w")
outfile.write(textbuffer.get_text(textbuffer.get_start_iter(),
textbuffer.get_end_iter(), include_hidden_chars=True))
outfile.close()
I'm new to Python and GTK and may not be asking the right type of
questions initially. I programmed with C many many years ago and my
programming instincts are very rusty so still feeling my way again
with this stuff. Apologies for the sarcastic reply earlier but i felt
your initial reply to be sarcastic. I also did research this problem
but seemed to be getting nowhere - thats why I asked for the groups
help.
Anyway, thanks to all that replied via emailed and in this group.
On Feb 18, 7:34 pm, Steven D'Aprano
<[EMAIL PROTECTED]> wrote:
> On Sat, 17 Feb 2007 17:10:50 -0800, google wrote:
> > I just included file opening code just to show how i read the file
> > into the text buffer - I have no issues with this as such. Problem is
> > only with the writing of the text buffer back to a file. When I try to
> > write the buffer to a file it gave the following,
>
> >
> > Traceback (most recent call last):
> > File "./configbox.py", line 78, in ?
> > TextViewExample()
> > File "./configbox.py", line 53, in __init__
> > outfile.write(textbuffer.get_text(0,1000,
> > include_hidden_chars=True))
> > TypeError: start should be a GtkTextIter
>
> Ah, well there's your problem. start should be a GtkTextIter, just like
> the exception says.
>
> Question for you: in the line of code in the traceback, which function
> takes an argument called "start"?
>
> > How can I use outfile.write() to wite the contents of the text buffer
> > correctly?
>
> Your problem isn't with outfile.write().
>
> --
> Steven.
--
http://mail.python.org/mailman/listinfo/python-list
Re: Getting a class name
On 18 Feb 2007 04:24:47 -0800, "Fuzzyman" <[EMAIL PROTECTED]> wrote: >On Feb 17, 8:33 pm, deelan <[EMAIL PROTECTED]> wrote: >> Harlin Seritt wrote: >> > Hi, >> >> > How does one get the name of a class from within the class code? I >> > tried something like this as a guess: >> >> > self.__name__ >> >> Get the class first, then inspect its name: >> >> >>> class Foo(object): pass >> ... >> >>> f = Foo() >> >>> f.__class__.__name__ >> 'Foo' >> >>> >> > > >Why is the __name__ attribute not available to the instance? Why don't >normal lookup rules apply (meaning that a magic attribute will be >looked up on the class for instances) ? Good question! >>> f = Foo() >>> dir(f) ['__class__', '__delattr__', '__dict__', '__doc__', '__getattribute__', '__hash__', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__str__', '__weakref__'] >>> dir(f.__class__) ['__class__', '__delattr__', '__dict__', '__doc__', '__getattribute__', '__hash__', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__str__', '__weakref__'] >>> Where is '__name__' ? Dan -- http://mail.python.org/mailman/listinfo/python-list
Re: Complex HTML forms
George Sakkis schrieb:
> I'd like to gather advice and links to any existing solutions (e.g.
> libraries, frameworks, design patterns) on general ways of writing
> complex web forms, as opposed to the typical {name:value} flat model.
> A particular case of what I mean by complex is hierarchical forms. For
> instance, a form that consists of a select list widget, where each
> item of the list activates a distinct set of other widgets. Think for
> example of a web frontend to CSV or SVN options and commands, where
> each command has its own suboptions. The suboptions are hidden (or
> even inexistent) until the user selects the specific command, and only
> then they appear (typically by Javascript). When the form is
> submitted, the selected options are passed in the server in some form
> that preserves the hierarchy, i.e. not as a flat dict. Is there
> anything close to such a beast around ?
formencode, which is heavily used in TurboGears. The dynamic parts
though you have to code yourself - but using mochikit, this is easy as
cake...
Diez
--
http://mail.python.org/mailman/listinfo/python-list
Re: Getting a class name
On Feb 18, 1:24 pm, "Fuzzyman" <[EMAIL PROTECTED]> wrote: > Why is the __name__ attribute not available to the instance? Why don't > normal lookup rules apply (meaning that a magic attribute will be > looked up on the class for instances) ? Because __name__ isn't really an attribute, it is a descriptor defined on the metaclass: >>> type(type.__dict__['__name__']) See http://users.rcn.com/python/download/Descriptor.htm for a guide to descriptors, and the papers by me and David Mertz for a guide to metaclasses. Michele Simionato -- http://mail.python.org/mailman/listinfo/python-list
Re: Help Required for Choosing Programming Language
Stef Mientki a écrit : (snip) > I'm not an (educated) programmer, so I don't always use the right terms :-( > If I look at a well established program like DIA, > and see that it still can't repaint it's screen always correctly, ... I suppose you're talking about the Diagram drawing program Dia. If so, I don't see how it is relevant to Python GUI programming since Dia is written in C with the GTK toolkit. The stability problems you experience have probably more to do with the status of the Windows port of GTK (which is originally a X toolkit). > I've been using Python for just 2 months, and didn't try any graphical > design, So how can you comment on GUI programming with Python ? -- http://mail.python.org/mailman/listinfo/python-list
Re: why I don't like range/xrange
[EMAIL PROTECTED] a écrit : > Bruno Desthuilliers wrote: > >>Roel Schroeven a ecrit : >> >>>Bruno Desthuilliers schreef: >>> >>> stdazi a ecrit : >>> >>> >for (i = 0 ; i < 10 ; i++) > i = 10; for i in range(10): i = 10 What's your point, exactly ? >>> >>> >>>In the first iteration, i is set equal to 10. Then, before starting the >>>second iteration, i is incremented to 11; then the loop condition is >>>checked and results in false. So the loop terminates after the first >>>iteration. >> >>oops - my bad. But why would one do so when a break would do the trick: >>for i in range(10): >> break > > > After the C loop finishes, i is 11. After the python loop-with-break > finishes, i is 0. That may effect later code. > Lord saves me from having to maintain programs based on such constructions... -- http://mail.python.org/mailman/listinfo/python-list
Re: Help Required for Choosing Programming Language
On 2/17/07, Stef Mientki <[EMAIL PROTECTED]> wrote: > Some examples: > - Creating a treeview (like in the M$ explorer), with full edit capabilities > and full drag & drop > facilities: Delphi takes about 40 lines of code (most of them even ^C ^V). > - Creating a graphical overview of relations between database tables, which > can be graphical > manipulated by the user (like in M$ Access): Delphi 20 lines of code. > I wonder what this costs in Python ? You really need to get your thinking straightened out. You can't compare Delphi to Python; Delphi is a product that uses Pascal as its language, while Python is a language. When you compare a product for a language to an entire language, it makes the rest of your arguments look silly. BTW, you said you looked at the Dabo Class Designer - did you know that that tool itself was written in Dabo? The power is there. The fact that you couldn't completely understand it in a brief review says more about you than it does about Python, wxPython or Dabo. -- # p.d. -- http://mail.python.org/mailman/listinfo/python-list
Re: Approaches of interprocess communication
Donn Cave wrote: > Quoth Steve Holden <[EMAIL PROTECTED]>: > | Ben Finney wrote: > ... > | > If a programmer decides on behalf of the user that "localhost" should > | > be treated specially, that programmer is making an error. > | > | Inter-process TCP/IP communication between two processes on the same > | host invariably uses the loopback interface (network 127.0.0.0). > | According to standards, all addresses in that network space refer to the > | local host, though 127.0.0.1 is conventionally used. > | > | The transmit driver for the loopback interface receives a datagram from > | the local network layer and immediately announces its reception back to > | the local network layer. > > Are you saying, in that first paragraph, that if for example I telnet to > my local host's external IP address, to a service that bound explicitly to > the external interface -- I'll actually be going through the loopback > interface anyway, invariably regardless of host network implementation? > I wasn't specifically saying that, no. However on Solaris I have observed local connections to an external interface actually increasing the packet count on the loopback, but I can't confirm whether those connections were to services specifically bound only to the external interface. Certainly on Windows XP there is a host-specific route via 127.0.0.1 to the external interfaces as well as the network route via the external interface. I wouldn't necessarily expect this to extend to other platforms. This is demonstrated by the following output from "route print". I have chopped the metric column to avoid line wrapping. = Active Routes: Network DestinationNetmask Gateway Interface 0.0.0.0 0.0.0.0 192.168.123.254 192.168.123.123 127.0.0.0255.0.0.0127.0.0.1 127.0.0.1 192.168.123.0255.255.255.0 192.168.123.123 192.168.123.123 192.168.123.123 255.255.255.255127.0.0.1 127.0.0.1 192.168.123.255 255.255.255.255 192.168.123.123 192.168.123.123 192.168.174.0255.255.255.0192.168.174.1 192.168.174.1 192.168.174.1 255.255.255.255127.0.0.1 127.0.0.1 192.168.174.255 255.255.255.255192.168.174.1 192.168.174.1 224.0.0.0240.0.0.0 192.168.123.123 192.168.123.123 224.0.0.0240.0.0.0192.168.174.1 192.168.174.1 255.255.255.255 255.255.255.255 192.168.123.123 3 255.255.255.255 255.255.255.255 192.168.123.123 192.168.123.123 255.255.255.255 255.255.255.255192.168.174.1 192.168.174.1 Default Gateway: 192.168.123.254 = regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC/Ltd http://www.holdenweb.com Skype: holdenweb http://del.icio.us/steve.holden Blog of Note: http://holdenweb.blogspot.com See you at PyCon? http://us.pycon.org/TX2007 -- http://mail.python.org/mailman/listinfo/python-list
function & class
hi friends, I have a program like some variable definations a function ( arg1, agr2): do something with arg1 & arg2 return a list if condition do this function(arg1,arg2) else if condition do this function else do this My problem is I want to use threading and I might need to pass values between function and classes. I am not sure how this can be done. I have read about classes and I know they are like function however does not return anything where as function does. If I define class and then function in this class how do I access this function ? I am not sure and confused about classes and functions as how to go about them is there any simple way to understand difference between them and when to use what and how to pass data/reference pointer between them ? @nil Pythonist -- http://mail.python.org/mailman/listinfo/python-list
Re: Getting a class name
On Feb 18, 1:22 pm, "Michele Simionato" <[EMAIL PROTECTED]>
wrote:
> On Feb 18, 1:24 pm, "Fuzzyman" <[EMAIL PROTECTED]> wrote:
>
> > Why is the __name__ attribute not available to the instance? Why don't
> > normal lookup rules apply (meaning that a magic attribute will be
> > looked up on the class for instances) ?
>
> Because __name__ isn't really an attribute, it is a descriptor defined
> on
> the metaclass:
>
> >>> type(type.__dict__['__name__'])
>
>
>
> Seehttp://users.rcn.com/python/download/Descriptor.htmfor a guide to
> descriptors, and the papers by me and David Mertz for a guide to
> metaclasses.
>
Thanks, I'll do some more reading.
I got as far as this on my own:
My guess is that it is because magic attributes are looked up on the
class. When you ask the *class* what its name is, the metaclass
answers on its behalf.
The class has no real ``__name__`` attribute, so when you ask the
instance (which doesn't inherit from the metaclass) you get an
``AttributeError``. Is this right ? In which case, how does the
metaclass (typically ``type`` which has many instance) know which
answer to supply ?
A simple test indicates that the name *is* looked up on the
metaclass :
.. raw:: html
{+coloring}
>>> class meta(type):
... __name__ = 'fish'
...
>>> class Test(object):
... __metaclass__ = meta
...
>>> Test.__name__
'fish'
{-coloring}
So maybe ``__name__`` is a propery and ``type`` keeps a dictionary of
instances to names, registered in ``type.__new__`` ?
Fuzzyman
http://www.voidspace.org.uk/python/articles.shtml
> Michele Simionato
--
http://mail.python.org/mailman/listinfo/python-list
Re: Dlls
Jason Ward wrote: > Hi. I am interested to know why python can't access DLL files directly. > It seems to me that because python can't access DLL's directly we have to > waste our time and write wrappers around libraries that have already > been written. > > So if the python developers were to implement say this. > > import MYDLL.dll > > Then we would be able to do everything with that library that we can do > in other languages. > > For eg. I want to use PyOpenGL. But the problem is the library hasn't > got all the opengl functions implemented. > So I can either develop quickly with an incomplete library or develop > slowly in assembler. > I mean really, in asm we just call the dll function directly. > > Why must python be different? > That's a bit like asking why you can't put the engine from a BMW into an Audi. The answer is, of course, that you can - it just required a lot of work to adapt the engine to a foreign environment. You might be interested in the ctypes module - see http://docs.python.org/lib/module-ctypes.html That does more or less what you are asking for, but you can't expect to be able to call arbitrary functions written in one language from another - there's just too much variability in the way that data are represented in different languages. There are, of course, systems like mono (.NET) that provide compilers for multiple languages with the specific goal of interoperability, but in general there will be an "impedance mismatch" that you will need to code around. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC/Ltd http://www.holdenweb.com Skype: holdenweb http://del.icio.us/steve.holden Blog of Note: http://holdenweb.blogspot.com See you at PyCon? http://us.pycon.org/TX2007 -- http://mail.python.org/mailman/listinfo/python-list
Re: Help Required for Choosing Programming Language
Stef Mientki schrieb: >>> - designing the GUI will cost me about 2 .. 3 times as much in Python >> >> You mean delphi here I presume? > No, but if that's your believe .. I'm sorry, that was a misreading of mine. > Some examples: > - Creating a treeview (like in the M$ explorer), with full edit > capabilities and full drag & drop > facilities: Delphi takes about 40 lines of code (most of them even ^C ^V). As does Qt. > - Creating a graphical overview of relations between database tables, > which can be graphical > manipulated by the user (like in M$ Access): Delphi 20 lines of code. > I wonder what this costs in Python ? Qt has data-aware classes, albeit I didn't play with them. > I've been using Python for just 2 months, and didn't try any graphical > design, > I've other priorities first. May I cite you: """ - Python is not capable of doing everything I need (almost all interactive actions are very primitive and crashes a lot) """ To me, that sounded like you were talking about gui-design. Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: Complex HTML forms
On Feb 18, 4:44 am, Gregor Horvath <[EMAIL PROTECTED]> wrote:
> George Sakkis schrieb:
>
> > I'd like to gather advice and links to any existing solutions (e.g.
> > libraries, frameworks, design patterns) on general ways of writing
> > complex web forms, as opposed to the typical {name:value} flat model.
> > A particular case of what I mean by complex is hierarchical forms. For
>
> http://toscawidgets.org/http://docs.turbogears.org/1.0/SimpleWidgetForm
>
> --
> Greg
Thank you all for the helpful replies. ToscaWidgets seems particularly
promising at a first glance, I'll look into it first.
Best,
George
--
http://mail.python.org/mailman/listinfo/python-list
Re: PyDev on Mac
On Feb 18, 4:50 am, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote: > Ahmer schrieb: > > > I've been trying to set up PyDev on my new MacBook Pro, but i have not > > had an success. > > > Could you please help! > > Just wait until my crystal ball comes back from the cleaners, and I will > start looking at your problem. > > As you can lay back and do nothing while that happens, I suggest you > take this highly entertaining read: > > http://www.catb.org/~esr/faqs/smart-questions.html > > Diez The main problem seems to be locating Python. Even though I installed the official python for mac, it says the interpreter is invalid. So I tried jPython, no succes on that either. It always tells me I am using an invlaid interpreter. -- http://mail.python.org/mailman/listinfo/python-list
Re: xml.dom.minidom memory usage
Dan wrote: > I'm using python's xml.dom.minidom module to generate xml files, and > I'm running into memory problems. Then take a look at cElementTree. It's part of Python 2.5 and is available as a separate module for Python 2.4. It's fast, has a very low memory profile and if you ever decide to need more features, there's lxml to the rescue. You might also consider streaming your XML piece by piece instead of creating in-memory trees. Python's generators are a good starting point here. Stefan -- http://mail.python.org/mailman/listinfo/python-list
search cursor in pythonwin 2.1
Hi all.
I am trying to create a little script(I think) that will basically use
a search cursor.
I am a GIS(geographic information systems) Analyst and in our
software(ESRI ARCGIS 9.1) ESRI has implemented Python 2.1 as the
scripting language of choice.
In my script I'm going thru a dbf file and extracting NON-NULL values
in a field. What I need to do with that is create a new dbf table with
the values I found in it.
Here is my sample code so far:
# This is a basic script for searching thru a table
# seeing if a field has a value, then writing that record
# to a brand new dbf
#
# Import basic modules
import win32com.client, sys, os, string
# Create the basic Geoprocessor Object
GP = win32com.client.Dispatch("esriGeoprocessing.GpDispatch.1")
# Make sure to setup proper licensce level from ESRI
GP.SetProduct("arcview")
# Set the input workspace - I WONT USE THE ARGUMENT DIALOG BOX
GP.Workspace = "E:/IntermediateGISProgrammingGEOG376/labs/
neighborhoods"
# THIS IS THE SPOT WHERE I'M MESSING UP
# I THINK AT THIS POINT I NEED TO:
# 1: OPEN THE SHAPEFILE
# 2: INITIALIZE THE FC VARIABLE
# 3: USE THE SEARCHCURSOR TO FIND THE RECORDS THAT HAVE A VALUE IN THE
NAME FIELD
# I looked in the Select Help file and a number of items popped up.
# However, I opened up Select -> analysis and it shows how to select
# from a shapefile. I assume this is what I need?
GP.Select_Analysis("neighborhoods.shp", "neighborhoods_names.shp", '
"Names" <> \ "null\" ')
#at this point I'm stuck. how do I query out a NON-
NULL value?
#or a value in the Names field?
Could anyone throw me a bone over here?
TIA
--
http://mail.python.org/mailman/listinfo/python-list
Re: PyDev on Mac
Ahmer schrieb: > On Feb 18, 4:50 am, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote: >> Ahmer schrieb: >> >>> I've been trying to set up PyDev on my new MacBook Pro, but i have not >>> had an success. >>> Could you please help! >> Just wait until my crystal ball comes back from the cleaners, and I will >> start looking at your problem. >> >> As you can lay back and do nothing while that happens, I suggest you >> take this highly entertaining read: >> >> http://www.catb.org/~esr/faqs/smart-questions.html >> >> Diez > > > The main problem seems to be locating Python. > > Even though I installed the official python for mac, it says the > interpreter is invalid. > So I tried jPython, no succes on that either. It always tells me I am > using an invlaid interpreter. crystal ball still not available. Who tells you what exactly when you do what? Is there a shell-script involved, what happens if you enter "python" at the commandline and press return? All this are uneccessary guessing games because you don't give enough context. Which is one of the many things mentioned on the site I suggested you to read. So I think you should read it again. Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: Getting a class name
On Feb 18, 9:17 am, "Gabriel Genellina" <[EMAIL PROTECTED]> wrote: > En Sun, 18 Feb 2007 04:20:33 -0300, goodwolf <[EMAIL PROTECTED]> > escribió: > > > I suppose that you wont get class name into its code (or before > > definition end) but not into a method definition. > > > import sys > > > def getCodeName(deap=0): > > return sys._getframe(deap+1).f_code.co_name > > > class MyClass (object): > > name = getCodeName() + '!' > > What's the advantage over MyClass.__name__? > > -- > Gabriel Genellina >>> class C(object): ... name = C.__name__ ... Traceback (most recent call last): File "", line 1, in ? File "", line 2, in C NameError: name 'C' is not defined >>> -- http://mail.python.org/mailman/listinfo/python-list
Re: Game Programming Clinic and Online Gaming at PyCon
On 2/17/07, Jeff Rush <[EMAIL PROTECTED]> wrote: At PyCon this year we're going to have a multi-day game programming clinic and challenge. This is a first-time event and an experiment to find those in the Python community who enjoy playing and creating games. Python has several powerful modules for the creation of games among which are PyGame and PyOpenGL. On Friday evening, Phil Hassey will give an introduction to his game Galcon, an awesome high-paced multi-player galactic action-strategy game. You send swarms of ships from planet to planet to take over the galaxy. Phil will be handing out free limited-time licenses to those present. He will also be glad to talk about the development of Galcon using PyGame. After the Friday PSF Members meeting lets out around 8:40pm, Richard Jones will give his 30-60 minute introduction to the PyGame framework so you too can get started writing games. Wonderful. Thanks for the heads-up! I look forward to this. On Saturday evening, Lucio Torre and Alejandro J. Cura, who have come from Argentina to give the talk "pyweek: making games in 7 days" Friday afternoon, will help people develop their games in the clinic room with mini-talks on various game technologies. Ah - that's a really fun presentation - I saw it at CafeConf. Glad to hear they'll be helping folks on Satyrday night. Thanks for all the links Jeff. Very helpful. -- cordially, Anna -- It is fate, but call it Italy if it pleases you, Vicar! -- http://mail.python.org/mailman/listinfo/python-list
Re: Dlls
Jason Ward wrote: > Hi. I am interested to know why python can't access DLL files directly. > It seems to me that because python can't access DLL's directly we have to > waste our time and write wrappers around libraries that have already > been written. > > So if the python developers were to implement say this. > > import MYDLL.dll > > Then we would be able to do everything with that library that we can > do in other languages. > > For eg. I want to use PyOpenGL. But the problem is the library hasn't > got all the opengl functions implemented. > So I can either develop quickly with an incomplete library or develop > slowly in assembler. > I mean really, in asm we just call the dll function directly. > > Why must python be different? Hi again, Jason, As we pointed out to you, ctypes *does* allow you to just load the DLL and start calling functions. In fact, that's how development tends to happen in the ctypes implementation. Someone just loads the DLL, hacks up a demo, I look at it and factor their code into the code-base. If there's some function missing that you need, do something like this: from OpenGL.platform import GL GL.myFunction( myParameter, myOtherParameter ) and if the parameters are of simple types, it will often "just work". If you want to pass arrays or similar data-types you'll need to make them ctypes arrays or pointers to use those "raw" functions, but they should work perfectly well. That is, you have to pass the right data-type, but then you'd have to do that in assembler too. Have fun, Mike -- Mike C. Fletcher Designer, VR Plumber, Coder http://www.vrplumber.com http://blog.vrplumber.com -- http://mail.python.org/mailman/listinfo/python-list
Re: function & class
jupiter a écrit :
> hi friends,
>
> I have a program like
>
> some variable definations
>
> a function ( arg1, agr2):
> do something with arg1 & arg2
> return a list
>
> if condition
>do this function(arg1,arg2)
> else
> if condition
> do this function
>else
> do this
>
>
> My problem is I want to use threading and I might need to pass values
> between function and classes.
which classes ? I see no class statement in your above pseudo-code.
> I am not sure how this can be done. I
> have read about classes and I know they are like function
Hmm. While technically, yes, Python classes are "callable" just like
functions are, this is mostly an implementation detail (or at least you
can consider it as such for now). Now from a conceptual POV, functions
and classes are quite different beasts.
> however does
> not return anything where as function does.
Where did you get such "knowledge", if I may ask ? Looks like you need a
better source of informations !-)
> If I define class and then
> function in this class how do I access this function ?
Classes are used to define and create ('instanciate' in OO jargon)
objects. Usually, one first creates an object, then calls methods on
this object:
class Greeter(object):
def __init__(self, name, saywhat=None):
self.name = name
if self.saywhat is None:
self.saywhat = "Hello %(who)s, greetings from %(name)s"
else:
self.saywhat = saywhat
def greet(self, who):
return self.saywhat % dict(name=self.name, who=who)
bruno = Greeter('Bruno')
print bruno.greet('Jupiter')
> I am not sure and confused about classes and functions as how to go
> about them is there any simple way to understand difference between
> them
Read a tutorial on OO ? Here's one:
http://pytut.infogami.com/node11-baseline.html
> and when to use what and how to pass data/reference pointer
> between them ?
In Python, everything you can name, pass to a function or return from a
function is an object.
> @nil
> Pythonist
>
--
http://mail.python.org/mailman/listinfo/python-list
Re: threading and multicores, pros and cons
In article <[EMAIL PROTECTED]>, Maric Michaud <[EMAIL PROTECTED]> wrote: > >This is a recurrent problem I encounter when I try to sell python >solutions to my customers. I'm aware that this problem is sometimes >overlooked, but here is the market's law. Could you expand more on what exactly the problem is? -- Aahz ([EMAIL PROTECTED]) <*> http://www.pythoncraft.com/ "I disrespectfully agree." --SJM -- http://mail.python.org/mailman/listinfo/python-list
Does Python have equivalent to MATLAB "varargin", "varargout", "nargin", "nargout"?
Thank you in advance for your response. Dmitrey -- http://mail.python.org/mailman/listinfo/python-list
Re: Does Python have equivalent to MATLAB "varargin", "varargout", "nargin", "nargout"?
[EMAIL PROTECTED] writes: > Thank you in advance for your response. And those do ... ? -- Jorge Godoy <[EMAIL PROTECTED]> -- http://mail.python.org/mailman/listinfo/python-list
Re: 'import dl' on AMD64 platform
John Pye <[EMAIL PROTECTED]> wrote: > I have a tricky situation that's preventing my Python/SWIG/C > application from running on the Debian Etch AMD64 platform. > > It seems that the 'dl' module is not available on that platform. The > only reason I need the 'dl' module, however, is for the values of > RTLD_LAZY etc, which I use with sys.setdlopenflags() in order to make > my imported SWIG module share its symbols correctly with more deeply- > nested plugin modiles in my C-code layer. > > I wonder if there is a workaround for this -- perhaps another way to > access the values of those RTLD flags? Read stuff out of /usr/include/bits/dlfcn.h ? It seems to be a constant 1 anyway #define RTLD_LAZY 0x1 You could try compiling the dl module by hand. -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list
Re: Does Python have equivalent to MATLAB "varargin", "varargout", "nargin", "nargout"?
Where you would use varargin and nargin in Matlab, you would use the *args mechanism in Python. Try calling def t1(*args): print args print len(args) with different argument lists Where you would use varargout and nargout in Matlab you would use tuple unpacking in Python. Play with this def t2(n): return tuple(range(n)) a, b = t2(2) x = t2(3) -- http://mail.python.org/mailman/listinfo/python-list
Re: function & class
Bruno Desthuilliers wrote:
> Classes are used to define and create ('instanciate' in OO jargon)
Good info from Bruno, just a quick note that it's spelled
"instantiate" (I'm not usually big on spelling corrections but since
you were teaching a new word I thought it might be worthwile).
--
http://mail.python.org/mailman/listinfo/python-list
Re: Does Python have equivalent to MATLAB "varargin", "varargout", "nargin", "nargout"?
On Feb 18, 12:58 pm, [EMAIL PROTECTED] wrote: > Thank you in advance for your response. > Dmitrey The Python equivalent to "varargin" is "*args". def printf(format, *args): sys.stdout.write(format % args) There's no direct equivalent to "varargout". In Python, functions only have one return value. However, you can simulate the effect of multiple return values by returning a tuple. "nargin" has no direct equivalent either, but you can define a function with optional arguments by giving them default values. For example, the MATLAB function function [x0, y0] = myplot(x, y, npts, angle, subdiv) % MYPLOT Plot a function. % MYPLOT(x, y, npts, angle, subdiv) % The first two input arguments are % required; the other three have default values. ... if nargin < 5, subdiv = 20; end if nargin < 4, angle = 10; end if nargin < 3, npts = 25; end ... would be written in Python as: def myplot(x, y, npts=25, angle=10, subdiv=20): ... -- http://mail.python.org/mailman/listinfo/python-list
Re: c++ for python programmers
Thomas Nelson wrote: > I realize I'm approaching this backwards from the direction most > people go, but does anyone know of a good c/c++ introduction for > python programmers? There's been lots of answers, but no-one's mentioned the book I like: * Accelerated C++ by Koenig & Moo It dives straight into C++ - rather than attempting to say "look, C++ is built ontop of C, so I'll teach you C first, I'll recognise that the idioms for developing in C++ are different and start from there instead". It's in my opinion by far and away one of the best intros I've read. (I'm not saying that lightly either - I rank it as good/language relevant an introduction as Learning Perl used to be, and the K&R book can be for many C developers). In many respects it'll also show you some of the similarities between python and C++, and the differences. Michael. -- http://mail.python.org/mailman/listinfo/python-list
window opens with os.system()
python help,
I'm testing on xpPro
I have a simple module that sends text files to a
printer. Then, it moves the file to the 'Fprtd'
directory. The module contains the following
code;
#
for n in PrtList:
os.system('type '+n+ ' > prn'
os.system('move '+n+ ' Fprtd')
#
os.system opens and closes a window for each file
it sends to the printer and again for each time
it moves a file to the Fprtd directory. If there
were only a few files, this wouldn't be so bad.
But, when the files number 300 to 400 it becomes
objectionable.
Is there any way to supress the flashing window.
xp no longer allows the 'ctty' command.
jim-on-linux
--
http://mail.python.org/mailman/listinfo/python-list
Re: string.find returns -1 when string evidently in source file
En Sun, 18 Feb 2007 07:04:27 -0300, bryan rasmussen
<[EMAIL PROTECTED]> escribió:
> the following is returning -1:
>
> x = open("latvian.txt",'r')
> x1 = x.read()
> print x1.find("LAYOUT")
> the encoding of the file is Unicode, I am able to return instances of
> individual characters but not whole words.
"Unicode" can't be the encoding. It's better to convert from bytes to
unicode objects just after reading, and then work on Unicode always.
x = open("latvian.txt",'r')
x1 = x.read().decode() # or .decode("utf8") or the right encoding for the
file
print type(x1) # should print
x1.find(u"LAYOUT")
--
Gabriel Genellina
--
http://mail.python.org/mailman/listinfo/python-list
Re: Getting a class name
En Sun, 18 Feb 2007 14:14:41 -0300, goodwolf <[EMAIL PROTECTED]> escribió: > On Feb 18, 9:17 am, "Gabriel Genellina" <[EMAIL PROTECTED]> wrote: >> En Sun, 18 Feb 2007 04:20:33 -0300, goodwolf <[EMAIL PROTECTED]> >> escribió: >> >> > I suppose that you wont get class name into its code (or before >> > definition end) but not into a method definition. >> >> > import sys >> >> > def getCodeName(deap=0): >> > return sys._getframe(deap+1).f_code.co_name >> >> > class MyClass (object): >> > name = getCodeName() + '!' >> >> What's the advantage over MyClass.__name__? >> >> -- >> Gabriel Genellina > class C(object): > ... name = C.__name__ > ... > Traceback (most recent call last): > File "", line 1, in ? > File "", line 2, in C > NameError: name 'C' is not defined I were asking, why do you want a "name" attribute since "__name__" already exists and has the needed information. And worst, using an internal implementation function to do such task. -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: search cursor in pythonwin 2.1
En Sun, 18 Feb 2007 13:12:20 -0300, GISDude <[EMAIL PROTECTED]>
escribió:
> I am a GIS(geographic information systems) Analyst and in our
> software(ESRI ARCGIS 9.1) ESRI has implemented Python 2.1 as the
> scripting language of choice.
>
> In my script I'm going thru a dbf file and extracting NON-NULL values
> in a field. What I need to do with that is create a new dbf table with
> the values I found in it.
I think you should either read the ArcGis documentation, or post your
question in a specilized forum.
Your problem is not about Python itself, but on how to use the
esriGeoprocessing object.
> GP.Select_Analysis("neighborhoods.shp", "neighborhoods_names.shp", '
> "Names" <> \ "null\" ')
>
>#at this point I'm stuck. how do I query out a NON-
> NULL value?
>#or a value in the Names field?
As a side note, on a standard SQL database, the condition would read
"Names IS NOT NULL", but I don't know if this is applicable or not.
--
Gabriel Genellina
--
http://mail.python.org/mailman/listinfo/python-list
Re: window opens with os.system()
En Sun, 18 Feb 2007 18:09:23 -0300, jim-on-linux <[EMAIL PROTECTED]>
escribió:
> I have a simple module that sends text files to a
> printer. Then, it moves the file to the 'Fprtd'
> directory. The module contains the following
> code;
>
>
> #
>
> for n in PrtList:
> os.system('type '+n+ ' > prn'
> os.system('move '+n+ ' Fprtd')
>
> #
>
> os.system opens and closes a window for each file
> it sends to the printer and again for each time
> it moves a file to the Fprtd directory. If there
> were only a few files, this wouldn't be so bad.
> But, when the files number 300 to 400 it becomes
> objectionable.
Just code the above in Python itself.
type xxx > prn == copy xxx prn == shutil.copyfile(xxx,prn)
move xxx Fprtd == shutil.move(xxx, Fprtd)
--
Gabriel Genellina
--
http://mail.python.org/mailman/listinfo/python-list
Re: function & class
jupiter wrote: > My problem is I want to use threading You're right. Why do you think you want to use (multi-)threading? > and I might need to pass values between function and classes. I am > not sure how this can be done. I have read about classes and I > know they are like function however does not return anything where > as function does. If I define class and then function in this > class how do I access this function ? I think you could read a tutorial about OOP, for example one of those: http://www.google.de/search?q=python+oop+tutorial Feel free to post here for further questions. > I am not sure and confused about classes and functions as how to > go about them is there any simple way to understand difference > between them and when to use what and how to pass data/reference > pointer between them ? BTW, please use some punctuation. Reading your multiline sentences isn't easy. Regards, Björn -- BOFH excuse #393: Interference from the Van Allen Belt. -- http://mail.python.org/mailman/listinfo/python-list
Re: numpy, numarray, or numeric?
In article <[EMAIL PROTECTED]>, "RickMuller" <[EMAIL PROTECTED]> wrote: > Use numpy; it is the "officially blessed one" that you refer to. It > has all of the advantages of the other two. > > Numeric was the first library, but it had some drawbacks that led some > people to develop Numarray, which had some additional features. > Finally, the numpy project was started to unify the two groups by > providing some of the new features in a code base consistent with the > old library as well. I agree completely, having converted all my code from Numeric to NumPy. Just my 2 cents. -- Lou Pecora (my views are my own) REMOVE THIS to email me. -- http://mail.python.org/mailman/listinfo/python-list
Toliet Seat Secrets
Toliet Seat - http://projectwiretap.blogspot.com/2007/02/toliet-seat-theater-presents.html Was Down apparently after Operations Hanger 36 unveiled its secret harrier stealth technology Feb, 18. approx 12:00 Thank you for another succesfull airshow says Kernel Clink. A 6 million dollar project amortization over 3 years. . -- http://mail.python.org/mailman/listinfo/python-list
Python Threads
Is there anyway to get 2 python threads to talk to one another?
I have a GUI which is spawning a thread to make a large calculation (that
way the GUI does not appear to be non responsive). I am trying to attach a
progress bar to the threaded action. As the thread is calculating data, I
would like it to communicate with the other (progress) thread to update it.
On windows, when I spawn the progress bar without using threads, the
progress bar stalls <> So I thought by
spawning the progress bar by using a thread, it would not stall... If
anyone can think of another technique I am all ears.
~~START SAMPLE
def progressBar(status):
mroot = Tkinter.Tk(className='Worker Bee')
metric = Meter(mroot, relief='ridge', bd=3)
metric.pack(fill='x')
metric.set(status, 'Starting ...')
def fetchFiles(file1,file2,file3):
method = ''
print file1
print file2
print file3
f1 = fopen(file1)
a = f1.readlines(); f1.close()
d1 = {}
for c in a:
for m in mailsrch.findall(c):
d1[m.lower()] = None
I Would like to Update the progress bar running in the other thread
here.
## set status = .33 and update progress bar.
if file2 == '':
domain(d1,file3)
#...
def startProc():
status = 0
thread.start_new_thread(fetchFiles, (f1name,f2name,f3name,))
thread.start_new_thread(progressBar, (status,))
~~END SAMPLE
--
http://mail.python.org/mailman/listinfo/python-list
unicodedata implementation
Hi, [Originally posted this to the dev list, but the moderator advised posting here first] I'm looking into implementing this module for Jython, and I'm trying to understand the contracts promised by the various methods. Please bear in mind that means I'm probably targeting the CPython implementation as of 2.3, although I would obviously be quite happy if my implementation doesn't need too much extra to fit the 2.5 functionality! As someone has previously posted [1], the documentation is a little thin and they were pointed at the Unicode specification [2]. I've done a little reading there, and have a little knowledge now, which is always dangerous. There are still gaps, and I was hoping someone here might be able to point out what I'm missing. My problem, described here [3], but I'll summarise and add a little to it. 2468;CIRCLED DIGIT NINE;No;0;EN; 0039;;9;9;N; (UnicodeData.txt [4] for Unicode 3.2.0 [5] entry for code-point 0x2468) verify(unicodedata.decimal(u'\u2468',None) is None) verify(unicodedata.digit(u'\u2468') == 9) verify(unicodedata.numeric(u'\u2468') == 9.0) That works fine, and I can see in the UnicodeData.txt file (the mirrored property N towards the end is a fine marker; go back three fields and then start working forward from there) that the decimal property isn't defined, the digit property is 9 and the numeric property is also 9. However, this next bit is what confuses me: 325F;CIRCLED NUMBER THIRTY FIVE;No;0;ON; 0033 0035;;;35;N; (UnicodeData.txt for Unicode 3.2.0 entry for code-point 0x325F) verify(unicodedata.decimal(u'\u325F',None) is None) verify(unicodedata.digit(u'\u325F', None) is None) verify(unicodedata.numeric(u'\u325F') == 35.0) The last one fails - ValueError: not a numeric character. Now, again looking at the UnicodeData.txt entry and the mirrored N property, working back three fields and going forward from there shows that the decimal property isn't set, the digit property isn't set and the numeric property appears to be 35. So from my understanding of the Unicode (3.2.0) spec, the code point 0x325F has a numeric property with a value of 35, but the python (2.3 and 2.4 - I haven't put 2.5 onto my box yet) implementation of unicodedata disagrees, presumably for good reason. I can't see where I'm going wrong. Cheers, James [1] http://groups.google.com/group/comp.lang.python/browse_frm/thread/39a894325686f329/7dbdda27be118836?lnk=st&q=unicodedata&rnum=10#7dbdda27be118836 [2] http://www.unicode.org/ [3] http://eternusuk.blogspot.com/2007/02/jython-unicodedata-initial-overview.html [4] http://www.unicode.org/Public/3.2-Update/UnicodeData-3.2.0.txt [5] http://www.unicode.org/Public/3.2-Update/UnicodeData-3.2.0.html -- http://mail.python.org/mailman/listinfo/python-list
Re: Dlls
Jason Ward wrote: > But in Assembler I can access any dll. Doesn't matter what language it > was written in. So this teaches us that Python isn't assembler language. > A dll contains machine code, so shouldn't any language be able to read > the functions. > Machine is the native language of a pc. > > btw, what's with the car analogies? They were an attempt to educate you. Never mind. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC/Ltd http://www.holdenweb.com Skype: holdenweb http://del.icio.us/steve.holden Blog of Note: http://holdenweb.blogspot.com See you at PyCon? http://us.pycon.org/TX2007 -- http://mail.python.org/mailman/listinfo/python-list
Re: Getting a class name
Gabriel Genellina a écrit : > En Sun, 18 Feb 2007 14:14:41 -0300, goodwolf <[EMAIL PROTECTED]> > escribió: > >> On Feb 18, 9:17 am, "Gabriel Genellina" <[EMAIL PROTECTED]> wrote: >> >>> En Sun, 18 Feb 2007 04:20:33 -0300, goodwolf <[EMAIL PROTECTED]> >>> escribió: >>> >>> > I suppose that you wont get class name into its code (or before >>> > definition end) but not into a method definition. >>> >>> > import sys >>> >>> > def getCodeName(deap=0): >>> > return sys._getframe(deap+1).f_code.co_name >>> >>> > class MyClass (object): >>> > name = getCodeName() + '!' >>> >>> What's the advantage over MyClass.__name__? >>> >>> -- >>> Gabriel Genellina >> >> > class C(object): >> >> ... name = C.__name__ >> ... >> Traceback (most recent call last): >> File "", line 1, in ? >> File "", line 2, in C >> NameError: name 'C' is not defined >> > > > I were asking, why do you want a "name" attribute since "__name__" > already exists and has the needed information. And worst, using an > internal implementation function to do such task. > This might be useful to avoid metaclass hacks when trying to initialize a class attribute that would require the class name. (my 2 cents) -- http://mail.python.org/mailman/listinfo/python-list
Re: window opens with os.system()
On Sunday 18 February 2007 17:27, Gabriel
Genellina wrote:
> En Sun, 18 Feb 2007 18:09:23 -0300,
> jim-on-linux <[EMAIL PROTECTED]>
>
> escribió:
> > I have a simple module that sends text files
> > to a printer. Then, it moves the file to the
> > 'Fprtd' directory. The module contains the
> > following code;
> >
> >
> > #
> >
> > for n in PrtList:
> > os.system('type '+n+ ' > prn'
> > os.system('move '+n+ ' Fprtd')
> >
Thanks Geneilina,
It works fine.
shutil.copyfile(xxx,prn)
jim-on-linux
> > #
> >
> > os.system opens and closes a window for each
> > file it sends to the printer and again for
> > each time it moves a file to the Fprtd
> > directory. If there were only a few files,
> > this wouldn't be so bad. But, when the files
> > number 300 to 400 it becomes objectionable.
>
> Just code the above in Python itself.
> type xxx > prn == copy xxx prn ==
> shutil.copyfile(xxx,prn) move xxx Fprtd ==
> shutil.move(xxx, Fprtd)
>
> --
> Gabriel Genellina
--
http://mail.python.org/mailman/listinfo/python-list
Re: PyDev on Mac
Ahmer wrote: > On Feb 18, 4:50 am, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote: >> Ahmer schrieb: >> >> > I've been trying to set up PyDev on my new MacBook Pro, but i have not >> > had an success. >> >> > Could you please help! >> >> Just wait until my crystal ball comes back from the cleaners, and I will >> start looking at your problem. >> >> As you can lay back and do nothing while that happens, I suggest you >> take this highly entertaining read: >> >> http://www.catb.org/~esr/faqs/smart-questions.html >> >> Diez > > > The main problem seems to be locating Python. > > Even though I installed the official python for mac, it says the > interpreter is invalid. > So I tried jPython, no succes on that either. It always tells me I am > using an invlaid interpreter. Are you pointing to the python directory in the eclipse/pydev config dialog ? hg -- http://mail.python.org/mailman/listinfo/python-list
Is there any way to automatically create a transcript of an interactive Python session?
Some languages, such as Scheme, permit you to make a transcript of an interactive console session. Is there a way to do that in Python? -- http://mail.python.org/mailman/listinfo/python-list
Re: Is there any way to automatically create a transcript of an interactive Python session?
In article <[EMAIL PROTECTED]>, "Jonathan Mark" <[EMAIL PROTECTED]> wrote: > Some languages, such as Scheme, permit you to make a transcript of an > interactive console session. Is there a way to do that in Python? I don't know of any way *inside* of python, but it's easy enough to run your interactive python session inside of something like "script", an emacs shell buffer, etc. -- http://mail.python.org/mailman/listinfo/python-list
Re: Getting a class name
On Feb 18, 11:54 pm, Bruno Desthuilliers <[EMAIL PROTECTED]> wrote: > Gabriel Genellina a écrit : > > > En Sun, 18 Feb 2007 14:14:41 -0300, goodwolf <[EMAIL PROTECTED]> > > escribió: > > >> On Feb 18, 9:17 am, "Gabriel Genellina" <[EMAIL PROTECTED]> wrote: > > >>> En Sun, 18 Feb 2007 04:20:33 -0300, goodwolf <[EMAIL PROTECTED]> > >>> escribió: > > >>> > I suppose that you wont get class name into its code (or before > >>> > definition end) but not into a method definition. > > >>> > import sys > > >>> > def getCodeName(deap=0): > >>> > return sys._getframe(deap+1).f_code.co_name > > >>> > class MyClass (object): > >>> > name = getCodeName() + '!' > > >>> What's the advantage over MyClass.__name__? > > >>> -- > >>> Gabriel Genellina > > > class C(object): > > >> ... name = C.__name__ > >> ... > >> Traceback (most recent call last): > >> File "", line 1, in ? > >> File "", line 2, in C > >> NameError: name 'C' is not defined > > > I were asking, why do you want a "name" attribute since "__name__" > > already exists and has the needed information. And worst, using an > > internal implementation function to do such task. > > This might be useful to avoid metaclass hacks when trying to initialize > a class attribute that would require the class name. (my 2 cents) It's still an ugly hack. :-) (But a nice implementation detail to know about none-the-less.) Fuzzyman http://www.voidspace.org.uk/python/articles.shtml -- http://mail.python.org/mailman/listinfo/python-list
Re: Help Required for Choosing Programming Language
On 2007-02-16, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > i have read about Python, Ruby and Visual C++. but i want to go > through with GUI based programming language like VB.net You might take a look at http://dabodev.com Dave Cook -- http://mail.python.org/mailman/listinfo/python-list
How to detect closing of wx.Panel?
Hi everybody, I have poblem with detecting closing of wx.Panel by user. How to detect that event? The wx.EVT_CLOSE event concerns wx.Frame class only. Neither Close() nor Destroy() aren't executed if the event occurs (if user close a panel). Thus extanding these both methods doesn't make sens (I've tested that). With many thanks & Best wishes, Jacek -- http://mail.python.org/mailman/listinfo/python-list
Re: Help Required for Choosing Programming Language
On Feb 16, 4:22 pm, [EMAIL PROTECTED] wrote: > I am VB6 programmer and wants to start new programming language but i > am unable to deciced. > > i have read about Python, Ruby and Visual C++. but i want to go > through with GUI based programming language like VB.net > > so will you please guide me which GUI based language has worth with > complete OOPS Characteristics > > will wait for the answer > > hope to have a right direction from you Programmer > > Regards > Iftikhar > [EMAIL PROTECTED] Despite what "real programmers" and various apologists might say, there isn't much out there that comes close to the ease-of-use and functionality of VB when it comes to designing a GUI. I say this not to discourage you, but to let you know that if a GUI designer is your sole criteria for a new language, you're going to be disappointed with everything you see. I'd suggest that with whatever new language you go with, you either write apps that aren't gui-based, or write a web application with a web-based GUI. Another alternative would be to write the "business logic" in the new language, and have a shell VB app implementing the GUI call it. You can do this easily in python by creating python based COM components (not sure how easy it is in ruby, and it's a comparitive pain-in-the-ass in C++) Good luck, Grant -- http://mail.python.org/mailman/listinfo/python-list
I need a crack for pyext1.2.5 plugin
Hi pythoneros. I'm a cuban guy interested in python and I need the crack of an Eclipse plugin: pyext 1.2.5 Thanks very much cheers Oliver Sosa -- http://mail.python.org/mailman/listinfo/python-list
Re: Need an identity operator because lambda is too slow
On Feb 17, 9:59 pm, "Deron Meranda" <[EMAIL PROTECTED]> wrote: [snip] this may be really dense, but i'm curious what's wrong with the "multiplexer" idiom: for item in some_sequence: item2 = (not some_rare_condition and item) or \ (some_rare_condition and some_transform_function(item)) . # more stuff peace stm -- http://mail.python.org/mailman/listinfo/python-list
Re: Python Threads
Well if this cannot be done, can a thread call a function in the main
method?
I have been trying and have not been successive. Perhaps I am using thread
incorrectly.
On 2/18/07, Sick Monkey <[EMAIL PROTECTED]> wrote:
Is there anyway to get 2 python threads to talk to one another?
I have a GUI which is spawning a thread to make a large calculation (that
way the GUI does not appear to be non responsive). I am trying to attach a
progress bar to the threaded action. As the thread is calculating data, I
would like it to communicate with the other (progress) thread to update it.
On windows, when I spawn the progress bar without using threads, the
progress bar stalls <> So I thought by
spawning the progress bar by using a thread, it would not stall... If
anyone can think of another technique I am all ears.
~~START SAMPLE
def progressBar(status):
mroot = Tkinter.Tk(className='Worker Bee')
metric = Meter(mroot, relief='ridge', bd=3)
metric.pack(fill='x')
metric.set(status, 'Starting ...')
def fetchFiles(file1,file2,file3):
method = ''
print file1
print file2
print file3
f1 = fopen(file1)
a = f1.readlines(); f1.close()
d1 = {}
for c in a:
for m in mailsrch.findall(c):
d1[m.lower()] = None
I Would like to Update the progress bar running in the other
thread here.
## set status = .33 and update progress bar.
if file2 == '':
domain(d1,file3)
#...
def startProc():
status = 0
thread.start_new_thread(fetchFiles, (f1name,f2name,f3name,))
thread.start_new_thread(progressBar, (status,))
~~END SAMPLE
--
http://mail.python.org/mailman/listinfo/python-list
Re: I need a crack for pyext1.2.5 plugin
On Feb 18, 8:07 pm, "Oliver Sosa Cano" <[EMAIL PROTECTED]> wrote: > Hi pythoneros. I'm a cuban guy interested in python and I need the crack of > an Eclipse plugin: pyext 1.2.5 > > Thanks very much > > cheers > > Oliver Sosa Never heard of pyext - Google turns up this link http://g.org/ext/py/, but this is pyext 0.2.0. If by "crack" you mean "bootlegged user key for commercial software," this is the wrong place for that stuff. On the other hand, if you tell us what kind of Eclipse work you are doing that requires this elusive plug-in, someone may have a suggestion on where to find it, or an equivalent. -- Paul -- http://mail.python.org/mailman/listinfo/python-list
Logging errors to a file
Is there any way to automatically log errors that occur within an executed script to a file? Thanks, Harlin -- http://mail.python.org/mailman/listinfo/python-list
Re: cmd all commands method?
On Feb 18, 8:59 pm, "Michele Simionato" <[EMAIL PROTECTED]>
wrote:
> On Feb 18, 10:49 am, "placid" <[EMAIL PROTECTED]> wrote:
>
> > On Feb 18, 7:17 pm, "Michele Simionato" <[EMAIL PROTECTED]>
>
> > > Yes, he is talking about the cmd
> > > module:http://docs.python.org/dev/lib/Cmd-objects.html.
> > > However that module was never intended as a real interpreter, so
> > > defining variables
> > > as the OP wants would require some work.
>
> > > Michele Simionato
>
> > How much work does it require ?
>
> Have you ever written an interpreter? It is a nontrivial job.
>
> Michele Simionato
No i have never written an interpreter and i can just imagine how much
work/effort is needed to write something like that.
If anyone can provide a suggestion to replicate the following Tcl
command in Python, i would greatly appreciate it.
namespace eval foo {
variable bar 12345
}
what this does is create a namespace foo with the variable bar set to
12345.
http://aspn.activestate.com/ASPN/docs/ActiveTcl/8.4/tcl/TclCmd/variable.htm
The code provided by Peter Otten is a good start for me. Cheers for
that!
Cheers
--
http://mail.python.org/mailman/listinfo/python-list
What is more efficient?
Let's say I have a class with few string properties and few integers, and a lot of methods defined for that class. Now if I have hundreds of thousands (or even more) of instances of that class - is it more efficient to remove those methods and make them separate functions, or it doesn't matter? Thanks... -- ___Karlo Lozovina - Mosor | | |.-.-. web: http://www.mosor.net || ICQ#: 10667163 | || _ | _ | Parce mihi domine quia Dalmata sum. |__|_|__||_|_| -- http://mail.python.org/mailman/listinfo/python-list
Re: What is more efficient?
On Feb 19, 2:17 pm, Karlo Lozovina <[EMAIL PROTECTED]> wrote: > Let's say I have a class with few string properties and few integers, and > a lot of methods defined for that class. > > Now if I have hundreds of thousands (or even more) of instances of that > class - is it more efficient to remove those methods and make them > separate functions, or it doesn't matter? What do you mean by efficient. Memory efficient? I would assume that making them separate functions would use less memory but would you sacrifice code readability for that (small?) of a memory saving? Good coding practice suggests that the methods should be bound to classes. > > Thanks... > > -- > ___Karlo Lozovina - Mosor > | | |.-.-. web:http://www.mosor.net|| ICQ#: 10667163 > | || _ | _ | Parce mihi domine quia Dalmata sum. > |__|_|__||_|_| Cheers -- http://mail.python.org/mailman/listinfo/python-list
Re: What is more efficient?
Hi Karlo, Now if I have hundreds of thousands (or even more) of instances of that class - is it more efficient to remove those methods and make them separate functions, or it doesn't matter? I can't get your idea from your text. Could you give us an example? Thanks... -- ___Karlo Lozovina - Mosor | | |.-.-. web: http://www.mosor.net || ICQ#: 10667163 | || _ | _ | Parce mihi domine quia Dalmata sum. |__|_|__||_|_| -- http://mail.python.org/mailman/listinfo/python-list -- Rintaro Masuda [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
RE: I need a crack for pyext1.2.5 plugin
Sorry if this is the wrong place to make that question. Pyext is a plugin that acoplate with pydev, it's 'software privativo' like said Stallman, but it's very interesting. I have version 1.2.5. I use Eclipse 'cos it's simply great!! If somebody could tell me some alternative... Thanks (sorry my english) On Feb 18, 8:07 pm, "Oliver Sosa Cano" <[EMAIL PROTECTED]> wrote: > Hi pythoneros. I'm a cuban guy interested in python and I need the crack of an Eclipse plugin: pyext 1.2.5 > > Thanks very much > > cheers > > Oliver Sosa Never heard of pyext - Google turns up this link http://g.org/ext/py/, but this is pyext 0.2.0. If by "crack" you mean "bootlegged user key for commercial software," this is the wrong place for that stuff. On the other hand, if you tell us what kind of Eclipse work you are doing that requires this elusive plug-in, someone may have a suggestion on where to find it, or an equivalent. -- Paul -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: numpy, numarray, or numeric?
I have the same doubt when I started using DataFrame class by Andrew Straw. When I used his code as it is, it didn't work because python can't find numeric module. But after I made a small change by 'import numpy' to his code, everything seems to work now. To me, it seems numpy works as same as numeric. HTH. On 2/15/07, Christian Convey <[EMAIL PROTECTED]> wrote: > I need to bang out an image processing library (it's schoolwork, so I > can't just use an existing one). But I see three libraries competing > for my love: numpy, numarray, and numeric. > > Can anyone recommend which one I should use? If one is considered the > officially blessed one going forward, that would be my ideal. > > Thanks, > Christian > -- > http://mail.python.org/mailman/listinfo/python-list > -- WenSui Liu A lousy statistician who happens to know a little programming (http://spaces.msn.com/statcompute/blog) -- http://mail.python.org/mailman/listinfo/python-list
Re: Python Threads
En Sun, 18 Feb 2007 23:37:02 -0300, Sick Monkey <[EMAIL PROTECTED]> escribió: > Well if this cannot be done, can a thread call a function in the main > method? > I have been trying and have not been successive. Perhaps I am using > thread > incorrectly. The safe way to pass information between threads is to use Queue. From inside the working thread, you put() an item with enough state information. On the main (GUI) thread, you use after() to check for any data in the queue, and then update the interfase accordingly. I think there is a recipe in the Python Cookbook http://aspn.activestate.com/ASPN/Cookbook/Python -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
ANN: java2python 0.2
java2python - Java to Python Source Code Translator --- java2python 0.2 Released 18 February 2007 What is java2python? -- java2python is a simple but effective tool to translate Java source code into Python source code. It's not perfect, and does not aspire to be. What's new in this release? -- Small enhancement: added converstion of "public static void main" method into module "if __name__ == '__main__' block. Better classmethod support: fixed class/instance member formatting strings to account for classmethods. Slightly more pythonic: replace "x == None" expressions with "x is None" in output code, also replace "x != None" with "x is not None". Bugfix: Fixed dotted type identifiers. Better exception translation: added support for mapping java exception types to python exception types. Support for non-local base class members: added support for base class members via config modules. Bugfix: changed single % characters to %% in expression format strings. Small enhancement: added support for 'methodPreambleSorter' configuration item. With this value, config modules can specify how to sort method preambles (typically decorators). Where can I get java2python? -- java2python is available for download from Google code: http://code.google.com/p/java2python/downloads/list Project page: http://code.google.com/p/java2python/ How do I use java2python? -- Like this: $ j2py -i input_file.java -o output_file.py The command has many options, and supports customization via multiple configuration modules. What are the requirements? -- java2python requires Python 2.5 or newer. Previous versions may or may not work. java2python requires ANTLR and PyANTLR to translate code, but translated code does not require ANTLR. What else? -- java2python is installed with distutils. Refer to the Python distutils documentation for more information. The digest version is: $ tar xzf java2python-0.2.tar.gz $ cd java2python-0.2 $ python setup.py install java2python is licensed under the GNU General Public License 2.0. No license is assumed of (or applied to) translated source. I'm very interested in your experience with java2python. Please drop me an note with any feedback you have. Troy Melhase mailto:[EMAIL PROTECTED] pgp7Fllr80es8.pgp Description: PGP signature -- http://mail.python.org/mailman/listinfo/python-list
Re: I need a crack for pyext1.2.5 plugin
Oliver Sosa Cano schrieb: > Sorry if this is the wrong place to make that question. It is the wrong place. > > Pyext is a plugin that acoplate with pydev, it's 'software privativo' > like said Stallman, but it's very interesting. You should ask Stallman how software developers should pay their bills and further ignore some of his drivel. > I have version 1.2.5. > I use Eclipse 'cos it's simply great!! > If somebody could tell me some alternative... The author of pydev-extension provides pydev FOR FREE!! If you want pydev-extension you should by a license. cheers Paul -- http://mail.python.org/mailman/listinfo/python-list
Re: Is there any way to automatically create a transcript of an interactive Python session?
Jonathan Mark wrote: > Some languages, such as Scheme, permit you to make a transcript of an > interactive console session. Is there a way to do that in Python? > Maybe IPython's logging feature is what you want? http://ipython.scipy.org/doc/manual/node6.html#SECTION00066000 Kent -- http://mail.python.org/mailman/listinfo/python-list
Re: Logging errors to a file
En Mon, 19 Feb 2007 00:00:35 -0300, Harlin Seritt <[EMAIL PROTECTED]> escribió: > Is there any way to automatically log errors that occur within an > executed script to a file? The logging module. You may want to enclose your main entry point in a try/except block, just to be sure you catch everything. (*Almost* everything; a multithreaded program may require additional catching of errors) -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: Need an identity operator because lambda is too slow
En Sun, 18 Feb 2007 23:31:53 -0300, Sean McIlroy <[EMAIL PROTECTED]> escribió: > On Feb 17, 9:59 pm, "Deron Meranda" <[EMAIL PROTECTED]> wrote: > [snip] > > this may be really dense, but i'm curious what's wrong with the > "multiplexer" idiom: > > for item in some_sequence: > item2 = (not some_rare_condition and item) or \ > (some_rare_condition and > some_transform_function(item)) > . # more stuff The main concern of the OP was that lambda x:x is slow, so it's better to move the condition out of the loop. Also, this and/or trick does not work when the Boolean value of item is false (like 0, (), []...) -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: Getting a class name
En Sun, 18 Feb 2007 20:56:48 -0300, Fuzzyman <[EMAIL PROTECTED]> escribió: > [somebody] wrote: >> >>> > def getCodeName(deap=0): >> >>> > return sys._getframe(deap+1).f_code.co_name >> >> >>> > class MyClass (object): >> >>> > name = getCodeName() + '!' >> >> >>> What's the advantage over MyClass.__name__? >> > I were asking, why do you want a "name" attribute since "__name__" >> > already exists and has the needed information. And worst, using an >> > internal implementation function to do such task. >> >> This might be useful to avoid metaclass hacks when trying to initialize >> a class attribute that would require the class name. (my 2 cents) > > It's still an ugly hack. :-) > (But a nice implementation detail to know about none-the-less.) Having class decorators would be nice... -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: What is more efficient?
En Mon, 19 Feb 2007 00:17:54 -0300, Karlo Lozovina <[EMAIL PROTECTED]> escribió: > Let's say I have a class with few string properties and few integers, and > a lot of methods defined for that class. > > Now if I have hundreds of thousands (or even more) of instances of that > class - is it more efficient to remove those methods and make them > separate functions, or it doesn't matter? I'm not sure what you mean, but normal methods are attached to the class, not to its instances. It doesn't matter whether you have 0 or a million instances, methods do not occupy more memory. -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: What is more efficient?
Karlo Lozovina wrote: > Let's say I have a class with few string properties and few integers, and > a lot of methods defined for that class. > > Now if I have hundreds of thousands (or even more) of instances of that > class - is it more efficient to remove those methods and make them > separate functions, or it doesn't matter? > > Thanks... > It is not noticeably more or less efficient in either memory or execution speed. Both method and function code is compiled and stored once in either the class name space (for the method) or the module name space (for the function), and the lookup of either one is a single lookup in the appropriate name space. Actually the method lookup requires one extra step: First look for the method in the instance (which fails) and then look for it in the class (which succeeds). But that extra look up is highly optimized and probably not noticeable. The number of methods/functions may slow things up, but it will affect either name space equally. Gary Herron -- http://mail.python.org/mailman/listinfo/python-list
Re: function & class
c.execute("select symbol,tvolume,date,time from "+self.dbase+"
where symbol=
?",t)
ProgrammingError: SQLite objects created in a thread can only be used
in that sa
me thread.The object was created in thread id 976 and this is thread
id 944
I am getting this error when I am using sql command within
class.function accessing from another class
how can I create seperate instance for sqlite objects ???
@nil
--
http://mail.python.org/mailman/listinfo/python-list
Re: What is more efficient?
On Feb 19, 4:38 pm, Gary Herron <[EMAIL PROTECTED]> wrote: > Karlo Lozovina wrote: > > Let's say I have a class with few string properties and few integers, and > > a lot of methods defined for that class. > > > Now if I have hundreds of thousands (or even more) of instances of that > > class - is it more efficient to remove those methods and make them > > separate functions, or it doesn't matter? > > > Thanks... > > It is not noticeably more or less efficient in either memory or > execution speed. well lucky i wont be designing/creating a new language! > > Both method and function code is compiled and stored once in either the > class name space (for the method) or the module name space (for the > function), and the lookup of either one is a single lookup in the > appropriate name space. > > Actually the method lookup requires one extra step: First look for the > method in the instance (which fails) and then look for it in the class > (which succeeds). But that extra look up is highly optimized and > probably not noticeable. The number of methods/functions may slow things > up, but it will affect either name space equally. > > Gary Herron -- http://mail.python.org/mailman/listinfo/python-list
bluetooth on windows.......
hi. i've been trying to access Bluetooth via python in windows Xp. py bluez for windows required something called _msbt. i'm running python 2.5. some problem with vb 7.1 compatibility. what do i do to get bluetooth up and running on Xp? -- http://mail.python.org/mailman/listinfo/python-list
Re: What is more efficient?
Karlo Lozovina wrote: > Let's say I have a class with few string properties and few integers, and > a lot of methods defined for that class. > > Now if I have hundreds of thousands (or even more) of instances of that > class - is it more efficient to remove those methods and make them > separate functions, or it doesn't matter? > > Thanks... > You'd do best to define the instance variable names in __slots__, and be sure to inherit from object. The methods don't matter (they all hang off the class anyway). The __slots__ will save you one reference per object for the __dict__. -- --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Re: Help Required for Choosing Programming Language
"Bruno Desthuilliers" <[EMAIL PROTECTED]> wrote: >Stef Mientki a écrit : >(snip) >> I've been using Python for just 2 months, and didn't try any graphical >> design, > >So how can you comment on GUI programming with Python ? I think we have a language problem here (no pun intended) When Stef says "Gui Programming" he means using something like Delphi or Boa to do the Graphical Layout, while on this group it normally means writing the python code to make your own windows etc., using Tkinter or better... There is no doubt that the first approach gets you going faster, albeit true that you have more flexibility with the second. The learning curves are also different, the first approach feeling less painful, as you seem to make progress from the start, and you don't have to worry about questions like : "whats a frame/toplevel/mainloop/etc.?" So from Stef's perspective he is right when he claims that Python's "Gui Programming" is poor - in the standard library it is non existent, as there are no Delphi-, Glade- or Boa-like tools available. And one can argue that something like Boa or the WX.. packages are not Python, as they are not included in the standard library... - Hendrik -- http://mail.python.org/mailman/listinfo/python-list
Re: bluetooth on windows.......
En Mon, 19 Feb 2007 03:04:33 -0300, srj <[EMAIL PROTECTED]> escribió: > i've been trying to access Bluetooth via python in windows Xp. > py bluez for windows required something called _msbt. > i'm running python 2.5. some problem with vb 7.1 compatibility. > > what do i do to get bluetooth up and running on > Xp? Python extensions must match the Python version up to the second digit. You have 3 choices: - try to find a PyBluez version already built for your Python 2.5 - install Python 2.4 and use the 2.4 version of PyBluez - recompile the extension yourself for 2.5 -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
generating Java bytecode
I would like to generate Java bytecode from Python source. I know this is possible using Jython, but I am having problems getting my code to run on Jython. Is there another way to get Java bytecode? Thanks. -- http://mail.python.org/mailman/listinfo/python-list
Re: How to detect closing of wx.Panel?
On Mon, 19 Feb 2007 01:18:11 +, Jacol wrote: > Hi everybody, > > I have poblem with detecting closing of wx.Panel by user. How to detect that > event? > Don't know why you want to do that, but you could register with the enclosing (hosting) widget. > The wx.EVT_CLOSE event concerns wx.Frame class only. Neither Close() nor > Destroy() aren't executed if the event occurs (if user close a panel). Thus > extanding these both methods doesn't make sens (I've tested that). > > With many thanks & > Best wishes, > Jacek Cheers Morpheus -- http://mail.python.org/mailman/listinfo/python-list
How do I create an array of functions?
I have a table of integers and each time I look up a value from the table I want to call a function using the table entry as an index into an array whose values are the different functions. I haven't seen anything on how to do this in python. TIA -- Time flies like the wind. Fruit flies like a banana. Stranger things have .0. happened but none stranger than this. Does your driver's license say Organ ..0 Donor?Black holes are where God divided by zero. Listen to me! We are all- 000 individuals! What if this weren't a hypothetical question? steveo at syslang.net -- http://mail.python.org/mailman/listinfo/python-list
FAQ maintenance with Python ...
Hello. I am trying to find Scott Witherell who graduated from WSHS and UVA. Do you know how I can get in touch with him? Michele Smith - Everyone is raving about the all-new Yahoo! Mail beta.-- http://mail.python.org/mailman/listinfo/python-list
