Re: "no variable or argument declarations are necessary."

2005-10-06 Thread Bengt Richter
On Wed, 05 Oct 2005 11:10:58 GMT, Ron Adam <[EMAIL PROTECTED]> wrote:

>Antoon Pardon wrote:
>> Op 2005-10-04, Ron Adam schreef <[EMAIL PROTECTED]>:
>> 
>>>Antoon Pardon wrote:
>>>
Op 2005-10-03, Steven D'Aprano schreef <[EMAIL PROTECTED]>:

>And lo, one multi-billion dollar Mars lander starts braking either too
>early or too late. Result: a new crater on Mars, named after the NASA
>employee who thought the compiler would catch errors.


Using (unit)tests will not guarantee that your programs is error free.

So if sooner or later a (unit)tested program causes a problem, will you
then argue that we should abondon tests, because tests won't catch
all errors.
>>>
>>>Maybe you need to specify what kind of errors you want to catch. 
>>>Different types of errors require different approaches.
>> 
>> 
>> I want to catch all errors of course.
>
>Yes, of course, and so do other programmers.  What I mean is to try and 
>break it down into specific instances and then see what the best 
>approach is for each one is.
>
>When I first started leaning Python I looked for these features as well, 
>but after a while my programming style changed and I don't depend on 
>types and names to check my data near as much now.  But instead write 
>better organized code and data structures with more explicit value 
>checks where I need them.
>
>My concern now is having reusable code and modules I can depend on.  And 
>also separating my data and data management operations from the user 
>interface.  Having functions and names that don't care what type the 
>objects are, makes doing this separation easier.
>
>Another situation where typeless names are useful is routines that 
>explicitly check the type, then depending on the type does different 
>things.  For example if you have a list with a lot of different type 
>objects stored in it, you can sort the contents into sublists by type.
>
>Looking at it from a different direction, how about adding a keyword to 
>say,  "from this point on, in this local name space, disallow new 
>names".  Then you can do...
>
>def few(x,y):
>a = 'a'
>b = 'b'
>i = j = k = l = None
>no_new_names
># raise an error after here if a new name is used.
>...
>for I in range(10):   <--  error
>   ...
>
>This is more suitable to Pythons style than declaring types or variables 
>I think.  Add to this explicit name-object locking to implement 
>constants and I think you would have most of the features you want.
>
You can do that now with a decorator, if you are willing to assign something
to no_new_names (so it won't give you a name error if it doesn't exist). E.g.,

 >>> def nnn(f):
 ... names = f.func_code.co_names
 ... assert 'no_new_names' not in names or names[-1]=='no_new_names', 'Bad 
name:%r'%names[-1]
 ... return f
 ...
 >>> @nnn
 ... def few(x,y):
 ... a = 'a'
 ... b = 'b'
 ... i = j = k = l = None
 ... no_new_names=None
 ... for i in range(10): print i,
 ...
 Traceback (most recent call last):
   File "", line 1, in ?
   File "", line 3, in nnn
 AssertionError: Bad name:'range'
 >>> @nnn
 ... def few(x,y):
 ... a = 'a'
 ... b = 'b'
 ... i = j = k = l = None
 ... no_new_names=None
 ... return a,b,i,j,k,l
 ...
 >>> few(123,456)
 ('a', 'b', None, None, None, None)

No guarantees, since this depends on the unguaranteed order of 
f.func_code.co_names ;-)

>so...
>
> no_new_names # limit any new names
> lock_name name   # lock a name to it's current object
That last one you could probably do with a decorator that imports dis and
checks the disassembly (or does the equivalent check of the byte code) of f
for STORE_FASTs directed to particular names after the lock_name name 
declaration,
which you would have to spell as a legal dummy statement like
lock_name = 'name'

or perhaps better, indicating a locked assignment e.g. to x by

x = lock_name = expr  # lock_name is dummy target to notice in disassembly, 
to lock x from there on
>
>
>Since names are stored in dictionaries,  a dictionary attribute to 
>disallow/allow new keys, and a way to set individual elements in a 
>dictionary to read only would be needed.  Once you can do that and it 
>proves useful, then maybe you can propose it as a language feature.
I would want to explore how to compose functionality with existing elements
before introducing either new elements or new syntax. E.g., the dictionaries
used for instance attribute names and values already exist, and you can already
build all kinds of restrictions on the use of attribute names via properties
and descriptors of other kinds and via __getattribute__ etc.

>
>These might also be checked for in the compile stage and would probably 
>be better as it wouldn't cause any slow down in the code or need a new 
>dictionary type.
Although note that the nnn decorator above does its checking at run time,
when the decorator is executed just after the _def_ is an

Re: Class methods

2005-10-06 Thread Steve Holden
Gerrit Holl wrote:
> Laszlo Zsolt Nagy wrote:
> 
>>>Oh man, it has been a long time I have read such an disturbing question.
>>>
>>>RTMF here:  http://docs.python.org/lib/built-in-funcs.html#l2h-14
>>> 
>>>
>>
>>I feel I was a bit harsh.
> 
> 
> Of course, those posts do keep the Google count for the famous
> four-letter-abbreviation down (-;
> 
> Gerrit.
> 
I'd been thinking it was about time the mucking fanual was updated.

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006  www.python.org/pycon/

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: dictionary interface

2005-10-06 Thread Bengt Richter
On 5 Oct 2005 08:23:53 GMT, Antoon Pardon <[EMAIL PROTECTED]> wrote:

>Op 2005-10-05, Tom Anderson schreef <[EMAIL PROTECTED]>:
>> On Tue, 4 Oct 2005, Robert Kern wrote:
>>
>>> Antoon Pardon wrote:
>>>
   class Tree:

 def __lt__(self, term):
   return set(self.iteritems()) < set(term.iteritems())

 def __eq__(self, term):
   return set(self.iteritems()) == set(term.iteritems())

 Would this be a correct definition of the desired behaviour?
>>>
>>> No.
>>>
>>> In [1]: {1:2} < {3:4}
>>> Out[1]: True
>>>
>>> In [2]: set({1:2}.iteritems()) < set({3:4}.iteritems())
>>> Out[2]: False
>>>
 Anyone a reference?
>>>
>>> The function dict_compare in dictobject.c .
>>
>> Well there's a really helpful answer. I'm intrigued, Robert - since you 
>> know the real answer to this question, why did you choose to tell the 
>> Antoon that he was wrong, not tell him in what way he was wrong, certainly 
>> not tell him how to be right, but just tell him to read the source, rather 
>> than simply telling him what you knew? Still, at least you told him which 
>> file to look in. And if he knows python but not C, or gets lost in the 
>> byzantine workings of the interpreter, well, that's his own fault, i 
>> guess.
>>
>> So, Antoon, firstly, your implementation of __eq__ is, i believe, correct.
>>
>> Your implementation of __lt__ is, sadly, not. While sets take "<" to mean 
>> "is a proper subset of", for dicts, it's a more conventional comparison 
>> operation, which constitutes a total ordering over all dicts (so you can 
>> sort with it, for example). However, since dicts don't really have a 
>> natural total ordering, it is ever so slightly arbitrary.
>>
>> The rules for ordering on dicts are, AFAICT:
>>
>> - If one dict has fewer elements than the other, it's the lesser
>> - If not, find the smallest key for which the two dicts have different 
>> values (counting 'not present' as a value)
>> -- If there is no such key, the dicts are equal
>> -- If the key is present in one dict but not the other, the dict in which 
>> it is present is the lesser
>> -- Otherwise, the dict in which the value is lesser is itself the lesser
>>
>> In code:
>>
>> def dict_cmp(a, b):
>>  diff = cmp(len(a), len(b))
>>  if (diff != 0):
>>  return diff
>>  for key in sorted(set(a.keys() + b.keys())):
>>  if (key not in a):
>>  return 1
>>  if (key not in b):
>>  return -1
>>  diff = cmp(a[key], b[key])
>>  if (diff != 0):
>>  return diff
>>  return 0
>>
>
>Thanks for the explanation, but you somehow give me too much.
>
>I have been searching some more and finally stumbled on this:
>
>http://docs.python.org/ref/comparisons.html
>
>  Mappings (dictionaries) compare equal if and only if their sorted
>  (key, value) lists compare equal. Outcomes other than equality are
>  resolved consistently, but are not otherwise defined.
>
"other outcomes" may not in general mean orderings are defined,
even when  ==  and != are well defined. E.g., below

>This seems to imply that the specific method to sort the dictionaries
>is unimported (as long as it is a total ordering). So I can use whatever
>method I want as long as it is achieves this.
>
>But that is contradicted by the unittest. If you have a unittest for
>comparing dictionaries, that means comparing dictionaries has a
>testable characteristic and thus is further defined.
>
>So I don't need a full implementation of dictionary comparison,
>I need to know in how far such a comparison is defined and
>what I can choose.
>
A couple of data points that may be of interest:

 >>> {'a':0j} < {'a':1j}
 Traceback (most recent call last):
   File "", line 1, in ?
 TypeError: cannot compare complex numbers using <, <=, >, >=

and
 >>> cmp(0j, 1j)
 Traceback (most recent call last):
   File "", line 1, in ?
 TypeError: cannot compare complex numbers using <, <=, >, >=

but
 >>> {'a':0j} == {'a':1j}
 False
 >>> {'a':1j} == {'a':1j}
 True

Regards,
Bengt Richter
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python, Mysql, insert NULL

2005-10-06 Thread Steve Holden
Thomas Bartkus wrote:
[...]
> 
> Others here have pointed out that the Python keyword "None" is converted to
> "Null" when passed to MySQL. I don't quite understand this and don't really
> care.  If I have a Python variable that has a value None, and I want to
> transmit this to MySQL as Null - I would:
> 
>if somevar == None:
>StrToConcatenateIntoSqlStatement = "Null"
>else:
>StrToConcatenateIntoSqlStatement = somevar
> 
> All of which assumes, of course, that the field you are targeting will
> accept a Null value.
> Thomas Bartkus
> 
> 
If you don't understand parameterized SQL queries you would do well to 
refrain from offering database advice :-)

Presumably you always check whether StrToConcatenateIntoSqlStatement 
contains no apostrophes before you actually construct the SQL?

Can we say "SQL injection exploit"?

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006  www.python.org/pycon/

-- 
http://mail.python.org/mailman/listinfo/python-list


Copy files to Linux server through ssh tunnel

2005-10-06 Thread durumdara
Hi !

I have some backup files on a server farm.
I want to store these local backup files on a backup file server for
"safety's snake".

These files are compressed zip files with 12 character length password.
But my system admin asked me, how can I improve the safety of the copy
operation, and the storing (now I use Samba share to store these files. I
map the SMB share on the client, copy these files, and unmap SMB).

Then I thinking to ssh protocol to improve protection.

The backup script is a py script. I see that Winscp can copy files through
ssh tunnel. Can I do it too ?
How ? How to I do it in pythonic way ?

Please help me with some examples or urls or other infos !

Thanks * 1000:
dd







--
1 Gbyte Ingyenes E-Mail Tárhely a MailPont-tól
http://www.mailpont.hu/

-- 
http://mail.python.org/mailman/listinfo/python-list


Copy files to Linux server through ssh tunnel

2005-10-06 Thread durumdara
Hi !

I have some backup files on a server farm.
I want to store these local backup files on a backup file server for
"safety's snake".

These files are compressed zip files with 12 character length password.
But my system admin asked me, how can I improve the safety of the copy
operation, and the storing (now I use Samba share to store these files. I
map the SMB share on the client, copy these files, and unmap SMB).

Then I thinking to ssh protocol to improve protection.

The backup script is a py script. I see that Winscp can copy files through
ssh tunnel. Can I do it too ?
How ? How to I do it in pythonic way ?

Please help me with some examples or urls or other infos !

Thanks * 1000:
dd







--
1 Gbyte Ingyenes E-Mail Tárhely a MailPont-tól
http://www.mailpont.hu/

-- 
http://mail.python.org/mailman/listinfo/python-list


Copy files to Linux server through ssh tunnel

2005-10-06 Thread durumdara
Hi !

I have some backup files on a server farm.
I want to store these local backup files on a backup file server for
"safety's snake".

These files are compressed zip files with 12 character length password.
But my system admin asked me, how can I improve the safety of the copy
operation, and the storing (now I use Samba share to store these files. I
map the SMB share on the client, copy these files, and unmap SMB).

Then I thinking to ssh protocol to improve protection.

The backup script is a py script. I see that Winscp can copy files through
ssh tunnel. Can I do it too ?
How ? How to I do it in pythonic way ?

Please help me with some examples or urls or other infos !

Thanks * 1000:
dd







--
1 Gbyte Ingyenes E-Mail Tárhely a MailPont-tól
http://www.mailpont.hu/

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Using command line args on Windows

2005-10-06 Thread Diez B. Roggisch
k8 wrote:
> Thank you thank you thank you- The windows command line sol worked.

It sure does. But it sucks.. bad tab-completion, few tools, short 
history, limited command-line-editing and so on. But if you want it the 
hard way, it's your choice :)

Diez
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: check html file size

2005-10-06 Thread Ulrich Hobelmann
Sherm Pendley wrote:
> I'm guessing you didn't get the joke then. I think Richard's response was a
> parody of Xah's "style" - a funny parody, at that.

If you take all the line noise in Perl as swearing ;)
I suppose I'm lucky I can't read it.

-- 
We're glad that graduates already know Java,
so we only have to teach them how to program.
somewhere in a German company
(credit to M. Felleisen and M. Sperber)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Copy files to Linux server through ssh tunnel

2005-10-06 Thread Martin Franklin
[EMAIL PROTECTED] wrote:
> Hi !
> 
> I have some backup files on a server farm.
> I want to store these local backup files on a backup file server for
> "safety's snake".
> 
> These files are compressed zip files with 12 character length password.
> But my system admin asked me, how can I improve the safety of the copy
> operation, and the storing (now I use Samba share to store these files. I
> map the SMB share on the client, copy these files, and unmap SMB).
> 
> Then I thinking to ssh protocol to improve protection.
> 
> The backup script is a py script. I see that Winscp can copy files through
> ssh tunnel. Can I do it too ?
> How ? How to I do it in pythonic way ?
> 
> Please help me with some examples or urls or other infos !
> 
> Thanks * 1000:
> dd
> 
> 
> 
> 
> 
> 
> 
> --
> 1 Gbyte Ingyenes E-Mail Tárhely a MailPont-tól
> http://www.mailpont.hu/
> 

See this:


http://www.lag.net/paramiko/


with this library you can use sftp to transfer you files.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python, Mysql, insert NULL

2005-10-06 Thread Python_it
Thanks for the many replies!
The problem was that is use '%s', i have to use %s and then my problem
is solved.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: "no variable or argument declarations are necessary."

2005-10-06 Thread Antoon Pardon
Op 2005-10-05, Mike Meyer schreef <[EMAIL PROTECTED]>:
> Antoon Pardon <[EMAIL PROTECTED]> writes:
 They also relieve a burden from the run-time, since all variables
 are declared, the runtime doesn't has to check whether or not
 a variable is accesible, it knows it is.
>>> Not in a dynamic language. Python lets you delete variables at run
>>> time, so the only way to know if a variable exists at a specific
>>> point during the execution of an arbitrary program is to execute the
>>> program to that point.
>> It is not perfect, that doesn't mean it can't help. How much code
>> deletes variables.
>
> It's not perfect means it may not help. Depends on the cost of being
> wrong - which means we need to see how things would be different if
> the code was assuming that a variable existed, and then turned out to
> be wrong.
>
> Actually, I'd be interested in knowing how you would improve the
> current CPython implementation with knowledge about whether or not a
> variable existed. The current implementation just does a dictionary
> lookup on the name. The lookup fails if the variable doesn't exist. So
> checking on the existence of the variable is a byproduct of finding
> the value of the variable. So even if it was perfect, it wouldn't
> help.

Yes it would. A function with a declare statement could work
as the __slots__ attribute in a class. AFAIU each variable
would then internally be associated with a number and the
dictionary would be replace by a list. Finding the value
of the variable would just be indexing this table.

 And if you provide type information with the declaration, more
 efficient code can be produced.
>>> Only in a few cases. Type inferencing is a well-understood
>>> technology, and will produce code as efficient as a statically type
>>> language in most cases.
>> I thought it was more than in a few. Without some type information
>> from the coder, I don't see how you can infer type from library
>> code.
>
> There's nothing special about library code. It can be anaylyzed just
> like any other code.

Not necessarily, library code may not come with source, so there
is little to be analyzed then.

>>> Except declarations don't add functionality to the language. They
>>> effect the programing process.
>> It would be one way to get writable closures in the language.
>> That is added functionality.
>
> Except just adding declerations doesn't give you that. You have to
> change the language so that undeclared variables are looked for up the
> scope.

They already are. The only exception being when the variable is
(re)bound. This can give you 'surprising' results like the
following.

a = []
b = []
def f():
  a[:] = range(10)
  b = range(10)

f()
print a
print b

which will gibe the following result.

[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
[]


>>> And we have conflicting claims about
>>> whether that's a good effect or not, all apparently based on nothing
>>> solider than personal experience. Which means the arguments are just
>>> personal preferences.
>> Whether the good effect is good enough is certainly open for debate.
>> But the opponents seem to argue that since it is no absolute guarantee,
>> it is next to useless. Well I can't agree with that kind of argument
>> and will argue against it.
>
> You're not reading the opponents arguments carefully enough. The
> argument is that the benefit from type declerations is overstated, and
> in reality doesn't outweigh the cost of declerations.

That may be there intend, but often enough I see arguments that boil
down to the fact that declarations won't solve a particular problem
completely as if that settles it.

>>> Dynamic languages tend to express a much wider range of programming
>>> paradigms than languages that are designed to be statically
>>> compiled. Some of these paradigms do away with - or relegate to the
>>> level of "ugly performance hack" - features that someone only
>>> experienced with something like Pascal would consider
>>> essential. Assignment statements are a good example of that.
>> I think we should get rid of thinking about a language as
>> static or dynamic. It is not the language which should determine
>> a static or dynamic approach, it is the problem you are trying
>> to solve. And if the coder thinks that a static approach is
>> best for his problem, why shouldn't he solve it that way.
>
> Except that languages *are* static or dynamic.

Not in the way a lot of people seem to think here. Adding declarations
doesn't need to take away any dynamism from the language.

> They have different
> features, and different behaviors. Rather than tilting at the windmill
> of making a dynamic language suitable for static approaches, it's
> better to simply use the appropriate tool for the job. Especially if
> those changes make the tool *less* suitable for a dynamic approach.

They don't. That seems to be the big fear after a lot of resistance
but IMO it is unfounded.

If I write a module that only makes sense with floating p

Re: "no variable or argument declarations are necessary."

2005-10-06 Thread Antoon Pardon
Op 2005-10-05, Diez B. Roggisch schreef <[EMAIL PROTECTED]>:
>> This is naive. Testing doesn't guarantee anything. If this is what you
>> think about testing, then testing gives you a false impression of
>> security. Maybe we should drop testing.
>
> Typechecking is done by a reduced lamda calculus (System F, which is 
> ML-Style), whereas testing has the full power of a turing complete 
> language. So _if_ one has to be dropped, it would certainly be 
> typechecking.

Sure, But allow me this silly analogy.

Going out on a full test-drive will also reveal your tires are flat.
So if you one has to be dropped, a full test drive or a tire check
it would certainly be the tired check. But IMO the tire check
is still usefull.

> Additionally, testing gives you the added benefit of actually using your 
> decelared APIs - which serves documentation  purposes as well as 
> securing your design decisions, as you might discover bad design while 
> actually writing testcases.

Hey, I'm all for testing. I never suggested testing should be dropped
for declarations

> Besides that, the false warm feeling of security a successful 
> compilation run has given many developers made them check untested and 
> actually broken code into the VCS. I've seen that _very_ often! And the 
> _only_ thinng that prevents us from doing so is to enforce tests.

I wonder how experienced are these programmers? I know I had this
feeling when I started at the univeristy, but before I left I
already wrote my programs in rather small pieces that were tested
before moving on.

> But 
> these are more naturally done in python (or similar languages) as every 
> programmer knows "unless the program run sucsessfully, I can't say 
> anything about it" than in a statically typed language where the 
> programmer argues "hey, it compiled, it should work!"

Again I do have to wonder about how experienced these programmers are.

-- 
Antoon Pardon
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: "no variable or argument declarations are necessary."

2005-10-06 Thread Duncan Booth
Antoon Pardon wrote:

>> from xml.dom import *
>>
>> def do_add(x, y):
>>  return '%s://%s' % (x, y)
>>
>> def do_something(node):
>>  if node.namespace == XML_NAMESPACE:
>>  return do_add('http://', node.namespace)
>>  elif node.namespace == ...
>>  ...
>>
> 
> IMO your variable are already mostly declared. The x and y in
> the do_add is kind of a declarartion for the parameters x and
> y. 

I think you missed his point, though I'm not surprised since unless you 
are familiar with the internals of the xml package it isn't obvious just 
how complex this situation is.

The value XML_NAMESPACE was imported from xml.dom, but the xml package is 
kind of weird. XML_NAMESPACE defined both in xml.dom and in the 
_xmlplus.dom package. The _xmlplus package is conditionally imported by the 
xml package, and completely replaces it, but only if _xmlplus is present 
and at least version 0.8.4 (older versions are ignored).

This is precisely the kind of flexibility which gives Python a lot of its 
power, but it means that you cannot tell without running the code which 
package actually provides xml.dom.

Of course, I would expect that if you enforced strict variable declarations 
you would also disallow 'from x import *', but you still cannot tell until 
runtime whether an particular module will supply a particular variable, not 
what type it is.
-- 
http://mail.python.org/mailman/listinfo/python-list


Help-log in to a web page

2005-10-06 Thread Murugesh
Hi all,
I'm a newbie to python.I need to login to a webpage after supplying 
usename and password.

import urllib   
sock = urllib.urlopen("http://xop-pc.main.com";)
htmlSource = sock.read()   
sock.close()   
print htmlSource

In the above code how can i supply username and password to that URL.
Thanks for you time.

Thanks
Amen.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: dictionary interface

2005-10-06 Thread Antoon Pardon
Op 2005-10-05, Steve Holden schreef <[EMAIL PROTECTED]>:
> Antoon Pardon wrote:
>> Op 2005-10-05, Steve Holden schreef <[EMAIL PROTECTED]>:
> [...]
>> 
>> Anyway, I have searched the source of the test for all testing
>> with regards to < and after some browsing back and fore it seems
>> it all boils down to the following two tests.
>> 
>>self.assert_(not {} < {})
>>self.assert_(not {1: 2} < {1L: 2L})
>> 
>
> So there isn't much to do, then! That's good. Seems you can pretty much 
> choose your own ordering.

Yes, I must have misunderstood something because I thought there also
was the following test:

  self.assert_({} < {1: 2})

Which is what prompted this thread from me.

> It would seem sensible to test a third case, namely
>
>  self.assert_(not {1L: 2L} < {1: 2})

I also though about adding the following test.

  dlst = range(20)
  for i in xrange(20):
dlst[i] = some_ramdom_dict()
  sort(dlst)
  for i in xrange(19):
for j in xrange(i+1,20):
  self.assert_(dlst[i] < dlst[j])


This would test for the consistency of the order, so that if a < b
and b < c that we also have a < c.

What do you think?

-- 
Antoon Pardon
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: "no variable or argument declarations are necessary."

2005-10-06 Thread Brian Quinlan
Paul Rubin wrote:
> Brian Quinlan <[EMAIL PROTECTED]> writes:
> 
>>OK. The Python compiler would check that the name is declared but it
>>would not check that it is defined before use? So this would be
>>acceptable:
>>
>>def foo():
>> local x
>> return x
> 
> 
> Come on, you are asking silly questions.  Any reasonable C compiler
> would flag something like that and Python (with the flag set) should
> do the same.  If you want to ask substantive questions, that's fine,
> but stop wasting our time with silly stuff.

I'm not trying to be silly. I am trying to get a handle on the semantics 
that you are proposing. So we now have two requirements for the new 
declaration syntax (please let me know if I'm wrong):

o the variable must be declared
o the variable must be assigned

I would assume that you would make it so that assignment and delaration 
happen as part of the same statement?

> If type checking is implemented then the stdlib should be updated to
> add declarations for public symbols.  If not, the compiler would flag
> the undeclared symbol.  You could always declare it to be of type 'object'.

Fair enough.

> 
>> try:
>>  unicode
>> except NameError:
>>  XML_NAMESPACE = "..."
>> else:
>>  XML_NAMESPACE = u"..."
> 
> 
> This wouldn't be allowed.

OK, that sucks.

> 
>>2. the compiler does not have access to the names in other modules anyway
> 
> 
> You're being silly again.  The compiler would examine the other module
> when it processes the import statement, just like it does now.

Right now, the compiler DOES NOT examine the contents of the other 
modules. All it does is generate an IMPORT_NAME instruction which is 
evaluation during runtime. So are you proposing that the compiler now 
scan other modules during compilation?

>>How would you find the class definition for the Node object at
>>compile-time? 
> 
> 
> By processing the xml.dom module when it's imported.

Import happens at runtime (see above). But you seem to want compile-time 
type checking.

Cheers,
Brian
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Help-log in to a web page

2005-10-06 Thread Laszlo Zsolt Nagy
Murugesh wrote:

>Hi all,
>I'm a newbie to python.I need to login to a webpage after supplying 
>usename and password.
>
>import urllib   
>sock = urllib.urlopen("http://xop-pc.main.com";)
>htmlSource = sock.read()   
>sock.close()   
>print htmlSource
>
>In the above code how can i supply username and password to that URL.
>Thanks for you time.
>  
>
xop-pc.main.com is not an existing site.
Can you tell me what kind of authentication method it is using?
If that is the "basic authentication" (defined the standard HTTP 
protocol) then you need to read this:

http://docs.python.org/lib/urlopener-objs.html

Basically, you need to subclass URLopener or FancyURLopener, and 
overwrite its "prompt_user_passwd" method.
That method will be then called whenever the server needs authentication.

Here is a template for you (untested):


from urllib import FancyURLOpener
class MyOpener(FancyURLOpener):
def prompt_user_passwd(host,realm):
   return ('myusername','mypassword')

opener = MyOpener({})
f = opener.open("http://xop-pc.main.com";)
try:
html_source = f.read()
finally:
f.close()



Best,

  Les






-- 
http://mail.python.org/mailman/listinfo/python-list


Class property (was: Class methods)

2005-10-06 Thread Laszlo Zsolt Nagy
Hughes, Chad O wrote:

> Is there any way to create a class method?  I can create a class 
> variable like this:
>
Hmm, seeing this post, I have decided to implement a 'classproperty' 
descriptor.
But I could not. This is what I imagined:

class A(object):
_x = 0
@classmethod
def get_x(cls):
print "Getting x..."
return cls._x
@classmethod
def set_x(cls,value):
print "Setting x..."
cls._x = value
x = classproperty(get_x,set_x)

Usage example:

 >>>print A.x
Getting x
0
 >>>A.x = 8
Setting x
 >>>print A.x
Getting x
8

I was trying for a while, but I could not implement a 'classproperty' 
function. Is it possible at all?
Thanks,

   Les




-- 
http://mail.python.org/mailman/listinfo/python-list


Re: "no variable or argument declarations are necessary."

2005-10-06 Thread Paul Rubin
Duncan Booth <[EMAIL PROTECTED]> writes:
> The value XML_NAMESPACE was imported from xml.dom, but the xml package is 
> kind of weird. XML_NAMESPACE defined both in xml.dom and in the 
> _xmlplus.dom package. The _xmlplus package is conditionally imported by the 
> xml package, and completely replaces it, but only if _xmlplus is present 
> and at least version 0.8.4 (older versions are ignored).
> 
> This is precisely the kind of flexibility which gives Python a lot of its 
> power, but it means that you cannot tell without running the code which 
> package actually provides xml.dom.

This sounds like the socket module, which is a total mess.  Library
code should not be written like that.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: "no variable or argument declarations are necessary."

2005-10-06 Thread Paul Rubin
Brian Quinlan <[EMAIL PROTECTED]> writes:
> I'm not trying to be silly. I am trying to get a handle on the
> semantics that you are proposing. So we now have two requirements for
> the new declaration syntax (please let me know if I'm wrong):
> 
> o the variable must be declared
> o the variable must be assigned

These would both be errors that the compiler could and should check
for, if declaration checking is enabled.  However, they would not be
syntax errors.

> I would assume that you would make it so that assignment and
> delaration happen as part of the same statement?

Sure, why not.

> Right now, the compiler DOES NOT examine the contents of the other
> modules. All it does is generate an IMPORT_NAME instruction which is
> evaluation during runtime. 

In that case the other module gets compiled when the IMPORT_NAME
instruction is executed.  That says that compile time and runtime are
really the same thing in the current system.

> So are you proposing that the compiler now scan other modules during
> compilation?

Yeah, maybe some optimization is possible.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Help-log in to a web page

2005-10-06 Thread Murugesh





Laszlo Zsolt Nagy wrote:
Murugesh wrote:
  
  
  Hi all,

I'm a newbie to python.I need to login to a webpage after supplying
usename and password.


import urllib   sock = urllib.urlopen("http://xop-pc.main.com")

htmlSource = sock.read()  
sock.close()   print
htmlSource    
In the above code how can i supply username and password to that URL.

Thanks for you time.

 


  
xop-pc.main.com is not an existing site.
  
Can you tell me what kind of authentication method it is using?
  
If that is the "basic authentication" (defined the standard HTTP
protocol) then you need to read this:
  
  
http://docs.python.org/lib/urlopener-objs.html
  
  
Basically, you need to subclass URLopener or FancyURLopener, and
overwrite its "prompt_user_passwd" method.
  
That method will be then called whenever the server needs
authentication.
  
  
Here is a template for you (untested):
  
  
  
from urllib import FancyURLOpener
  
class MyOpener(FancyURLOpener):
  
   def prompt_user_passwd(host,realm):
  
  return ('myusername','mypassword')
  
  
opener = MyOpener({})
  
f = opener.open("http://xop-pc.main.com")
  
try:
  
   html_source = f.read()
  
finally:
  
   f.close()
  
  
  
  
Best,
  
  
 Les
  
  
  


I tried to view the source,it has,
  
 
 src=""
height="80">* User Name
    pan>
    id="username" class="x4"  name="j_username" size="30"
    type="text"
value="myadmin">
   
class="xc">* Password
    >
  
  




-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Class property (was: Class methods)

2005-10-06 Thread Peter Otten
Laszlo Zsolt Nagy wrote:

> I was trying for a while, but I could not implement a 'classproperty'
> function. Is it possible at all?

You could define a "normal" property in the metaclass:

> class A:
... class __metaclass__(type):
... @property
... def clsprp(cls): return 42
...
>>> A.clsprp
42

Peter

-- 
http://mail.python.org/mailman/listinfo/python-list


Compile as static

2005-10-06 Thread tjue1
Hello List

Has anyone had any luck with this? Im trying to compile python 2.4.2 on
Slackware 10.1 into one large executable. One which contains everything
required to run python (as static). So python doesn't look for
dynamically shared objects like libpthread.so.0.

I have tried ./configure --disable-dynamic
 --enable-dynamic=NO
 --enable-static

However the executable size is always the same :/ Please assist.

Thank You

Matt
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Help-log in to a web page

2005-10-06 Thread Murugesh




Murugesh wrote:

  
  
Laszlo Zsolt Nagy wrote:
  Murugesh wrote: 

Hi all, 
I'm a newbie to python.I need to login to a webpage after supplying
usename and password. 
  
import urllib   sock = urllib.urlopen("http://xop-pc.main.com") 
htmlSource = sock.read()  
sock.close()   print
htmlSource    
In the above code how can i supply username and password to that URL. 
Thanks for you time. 
  
  

xop-pc.main.com is not an existing site. 
Can you tell me what kind of authentication method it is using? 
If that is the "basic authentication" (defined the standard HTTP
protocol) then you need to read this: 

http://docs.python.org/lib/urlopener-objs.html


Basically, you need to subclass URLopener or FancyURLopener, and
overwrite its "prompt_user_passwd" method. 
That method will be then called whenever the server needs
authentication. 

Here is a template for you (untested): 


from urllib import FancyURLOpener 
class MyOpener(FancyURLOpener): 
   def prompt_user_passwd(host,realm): 
  return ('myusername','mypassword') 

opener = MyOpener({}) 
f = opener.open("http://xop-pc.main.com") 
try: 
   html_source = f.read() 
finally: 
   f.close() 



Best, 

 Les 


  
  
I tried to view the source,it has,
  
 
 src=""
height="80">* User Name
    pan>
    id="username" class="x4"  name="j_username" size="30"
    type="text"
value="myadmin">
   
class="xc">* Password
    >
  


Les,
I tried your code and it hangs.I believe the authentication is
different from the standard one.

Any help will be appreciated.

Thanks
Amen

   

  
  




-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Help-log in to a web page

2005-10-06 Thread Chris Dewin
On Thu, 06 Oct 2005 14:51:31 +0530, Murugesh wrote:

>  id="username" class="x4" onkeypress="return
> _submitOnEnter(event, 'User');" name="j_username" size="30"
> type="text" value="myadmin">

I'm a novice too. But that looks to me like a javascript method. At a
guess, it probably re directs the browser to some web script which checks
the password.

If so, knowing the address of that script, and the names of the keys it's
expecting would be useful to you. They might be in the 
section of the page. If not, they might be contained in a *.js file
somewhere.

I have no idea whether this helpful at all. Just consider it speculation.
-- 
www.wintergreen.in

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Swig and pointers

2005-10-06 Thread Miki Tebeka
Hello Java,

> ...
> extern int doIt(char *a, MY_DIGIT **digit);
> %include cpointer.i
> %pointer_functions(MY_DIGIT, md_prt);
Don't you mean md_ptr?

> %typemap(in) (char *a, MY_DIGIT **argv) {
>   /* Check if is a list */
>   if (PyList_Check($input)) {
> int i;
> $1 = PyList_Size($input);
> $2 = (MY_DIGIT **) malloc(($1+1)*sizeof(long *));
> for (i = 0; i < $1; i++) {
>   PyObject *o = PyList_GetItem($input,i);
>   if (PyString_Check(o))
>   $2[i] = PyString_AsString(PyList_GetItem($input,i));
>   else {
>   PyErr_SetString(PyExc_TypeError,"list must contain strings");
>   free($2);
>   return NULL;
>   }
> }
> $2[i] = 0;
>   } else {
> PyErr_SetString(PyExc_TypeError,"not a list");
> return NULL;
>   }
> }
> 
> %typemap(freearg) (char *a, MY_DIGIT **argv) {
>   free((MY_DIGIT *) $2);
> }
> 
> 
> ..from Python I am trying
> 
> >> ptr = []
> >> doIt("blah", ptr)
> 
> I thought this was the correct approach as described here:
> http://www.swig.org/Doc1.3/SWIGDocumentation.html#Python_nn59
> 
> However, python comes back and says "TypeError: argument number 2: a
> 'MY_DIGIT **' is expected, 'list([])' is received"
> 
> ..any ideas? 
Didn't check it but from http://www.swig.org/Doc1.3/Library.html it looks
like you need to do:
ptr = new_md_prt()

HTH.
--

Miki Tebeka <[EMAIL PROTECTED]>
http://tebeka.bizhat.com
The only difference between children and adults is the price of the toys


pgpti3bVY1t95.pgp
Description: PGP signature
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Extending Python

2005-10-06 Thread Miki Tebeka
Hello Tuvas,

> I am looking for a good tutorial on how to extend python with C code. I
> have an application built in C that I need to be able to use in Python.
http://www.swig.org/Doc1.3/Python.html#Python

> I have searched through various sources, starting of course with the
> Python site itself, and others, but I felt a bit lacking from the
> Python site, it seems it was only made for those who installed the
> source distribution, as for the other people... 
If you think something is missing from http://docs.python.org/ext/ext.html
please tell us.

> Anyways, thanks for the help!
You're welcome.

Bye.
--

Miki Tebeka <[EMAIL PROTECTED]>
http://tebeka.bizhat.com
The only difference between children and adults is the price of the toys


pgpnPt1Q2pzVs.pgp
Description: PGP signature
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: "no variable or argument declarations are necessary."

2005-10-06 Thread Diez B. Roggisch
> Sure, But allow me this silly analogy.
> 
> Going out on a full test-drive will also reveal your tires are flat.
> So if you one has to be dropped, a full test drive or a tire check
> it would certainly be the tired check. But IMO the tire check
> is still usefull.

But you could write it as test - including not only a look (which 
resembles the limited capabilities of typechecking), but testing the air 
pressure, looking at the tyre type and see that it won't match the rainy 
conditions...

> Hey, I'm all for testing. I never suggested testing should be dropped
> for declarations

The testing is IMHO more valuable than typechecking. The latter one 
actually _limits_ me. See e.g. the java IO-Api for a very bloated way of 
what comes very naturally with python. Duck-typing at it's best. The 
only reason I see typechecking is good for is optimization. But that is 
not the problem with JAVA/.NET anyway. And could possibly be done with 
psyco.

> I wonder how experienced are these programmers? I know I had this
> feeling when I started at the univeristy, but before I left I
> already wrote my programs in rather small pieces that were tested
> before moving on.



> Again I do have to wonder about how experienced these programmers are.

Well - surely they aren't. But that is beyond your control - you can't 
just stomp into a company and declare your own superiority and force 
others your way. I was astonished to  hear that even MS just recently 
adopted test-driven development for their upcoming windows vista. And 
they are commonly seen as sort of whiz-kid hiring hi-class company, 
certified CMM Levelo 6 and so on

The discussion is somewhat moot - typechecking is not nonsense. But 
matter of factly, _no_ programm runs without testing. And developing a 
good testing culture is cruicial. Where OTH a lot of large and 
successful projects exist (namely the python ones, amongst others..) 
that show that testing alone without typechecking seems to be good enough.

Diez
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Help-log in to a web page

2005-10-06 Thread Laszlo Zsolt Nagy

>>
>> I tried to view the source,it has,
>>   
>>  
>>  src="/em/cabo/images /t.gif" height="80">> align="center" border="0" cellspacing="2" cellpadding="0">> id="username
>> __xc_">> title="Required" class="xc">* *User Name> pan>> width="12">> id="username" class="x4" onkeypress="return 
>> _submitOnEnter(event, 'User');" name="j_username" size="30"
>> type="text" value="myadmin">> nowrap>> class="xc">* Password> width="12">> >> name="j_password" size="30*" autocomplete="off" type="p
>> ...
>> ...
>
Either it is a javascript or a form. Most likely this will be a normal 
form, like:


  
  


This is another authentication method that is used frequently. You need 
to POST the login/password and other parameters to the URL specified by 
the "action" attribute of the "form" tag.

Say, if you download the above HTML page from http://here.net/there

then you should POST your login data  to

http://here.net/there/login.php

The response may contain cookies - you need to use them to keep yourself 
logged in.

Please read documentation about these:

- HTML forms
- HTTP cookies

and then read the docs of the urllib module here:

http://www.python.org/doc/current/lib/module-urllib.html

It has parts where you can learn how to POST or GET data.
If you need to handle cookies as well (probably, this is true in your 
case), you might want to change to urllib2

http://www.python.org/doc/current/lib/module-urllib2.html

because it has support for cookies.

Don't do anything until you understand what cookies and HTML forms are.
(And don't ask about them here - it is not about Python programming...)

Best,

   Les
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Can Python replace TCL/Expect

2005-10-06 Thread Cameron Laird
In article <[EMAIL PROTECTED]>,
Robert Kern  <[EMAIL PROTECTED]> wrote:
>[EMAIL PROTECTED] wrote:
>> Hi
>> 
>> I'm learning Python. I don't know whether Python can do something like
>> Expect can do. If yes, please show me how to do it.
>> I want to do something automatically: open connection to a ftp server,
>> get the welcome message on the screen (not in the packet). I can do it
>> easily with Expect but I still don't have any idea with Python.
>> If possible, can you introduce me some book or website that I can get
>> infor about automation programming with Python
>
>You'll probably want to take a look at pexpect:
>
>  http://pexpect.sourceforge.net/
.
.
.
1.  Yes.
2.  While Pexpect indeed "can do something like Expect", 
it does NOT have all the facilities and polish of the
latter.
3.  But very, VERY few of Expect's users are aware of more
than a handful of Expect's functions, let alone use them,
so it's fair to say that Pexpect does everything Expect
does, within the realm of ordinary use.
4.  But it sort-of doesn't matter anyway, because, if the
goal is (as appears in this case) to work with ftp, 
there are better ways to work, anyway http://phaseit.net/claird/comp.unix.programmer/ftp_automation.html >
http://www.python.org/doc/current/lib/ftp-handler-objects.html >.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: "no variable or argument declarations are necessary."

2005-10-06 Thread Antoon Pardon
Op 2005-10-06, Diez B. Roggisch schreef <[EMAIL PROTECTED]>:
>> Sure, But allow me this silly analogy.
>> 
>> Going out on a full test-drive will also reveal your tires are flat.
>> So if you one has to be dropped, a full test drive or a tire check
>> it would certainly be the tired check. But IMO the tire check
>> is still usefull.
>
> But you could write it as test - including not only a look (which 
> resembles the limited capabilities of typechecking), but testing the air 
> pressure, looking at the tyre type and see that it won't match the rainy 
> conditions...
>
>> Hey, I'm all for testing. I never suggested testing should be dropped
>> for declarations
>
> The testing is IMHO more valuable than typechecking. The latter one 
> actually _limits_ me. See e.g. the java IO-Api for a very bloated way of 
> what comes very naturally with python. Duck-typing at it's best.

But typechecking doesn't has to be java like.

I can't help but feel that a lot of people have specific typechecking
systems in mind and then conclude that the limits of such a symtem
are inherent in typechecking itself.

IMO a good type system doesn't need to limit python in any way.

-- 
Antoon Pardon
-- 
http://mail.python.org/mailman/listinfo/python-list


/usr/bin/env python, force a version

2005-10-06 Thread manatlan
I've got a trouble, and i think that anybody there can help me

I've got a python script which i distribute in somes packages for *nix.
This script is full of python and need python 2.4 ! And i'd like to
display a message when the user doesn't have a python2.4 version.

if i put, at the top of the script (which can be done with /usr/bin env
too):

#/usr/bin/python2.4
it will be good, but py2.3 users can't run the script, and the message
comes from the system ;-( ... it can't be a message from my script ;-(

#/usr/bin/python2.3
it will not be good, because my scrill will not work at all ;-)

#/usr/bin/python
it will select the defined python version of the platform ... And here
is the problem. On debian/sid, users have python2.3 (default), et py2.4
: So the script will start with 2.3, and my message will be displayed.
But it could work because there is a py2.4 on the machine ;-(.

I'd like to make my script (or a starter script)
which will be able to detect all python versions of the machine. And
run my script with the good one ; py2.4, or display a message to the
user to say her it must install py2.4 ...

I hope you understand my needs. Is there a python/bash mechanism to
override the default python version of the system ...  and run the
script with any version of python (but the most recent) ?
or can you explain me how to do that ? the simplest way ?

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: replacments for stdio?

2005-10-06 Thread Ido . Yehieli
yes,
I've tried it aswell - nice work indeed!

now, maybe also get stdin to work from this TK window... ;-)

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: /usr/bin/env python, force a version

2005-10-06 Thread Laszlo Zsolt Nagy
[EMAIL PROTECTED] wrote:

>I've got a trouble, and i think that anybody there can help me
>
>I've got a python script which i distribute in somes packages for *nix.
>This script is full of python and need python 2.4 ! And i'd like to
>display a message when the user doesn't have a python2.4 version.
>  
>
 >>> import sys
 >>> sys.version
'2.4.1 (#65, Mar 30 2005, 09:13:57) [MSC v.1310 32 bit (Intel)]'
 >>>

There is also

sys.hexversion
sys.api_version
sys.version_info*

Read this:

*http://docs.python.org/lib/module-sys.html


  Les

**
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: replacments for stdio?

2005-10-06 Thread Ido . Yehieli
the source (and Bryan) doesn't say anything about further distribution
- and he did not provide a real email address.
Can I safely modify it and include it in the source distribution of my
program (it is open source licensed)? Would that be the polite thing to
do, i have no idea how to contact this guy?

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: "no variable or argument declarations are necessary."

2005-10-06 Thread Brian Quinlan
Paul Rubin wrote:

 >> Right now, the compiler DOES NOT examine the contents of the other
 >> modules. All it does is generate an IMPORT_NAME instruction which is
 >> evaluation during runtime.
 >
 >
 >
 > In that case the other module gets compiled when the IMPORT_NAME
 > instruction is executed.


If compilation is required to complete the import (i.e. the module has 
not already been imported and the module does not already have a 
compiled byte-code file) then that is the same.

 > That says that compile time and runtime are
 > really the same thing in the current system.


I would say that they are separate systems but that the compilation 
system is available to the runtime (but not vise-versa). In any case, 
the important thing is that the operation of these systems has an impact 
on the optional declaration proposal being discussed.

The thing that I'm trying to understand is how the proponents of such a 
system would change Python to accomodate it. No one has been able to 
articulate that with any decree of specifity ("Just do what Perl does"). 
Also, these (poorly-defined) proposals have revealed a lack of 
understanding of Python's existing workings ("The compiler would examine 
the other module when it processes the import statement, just like it 
does now.").

Without a clear idea of the nature of the proposal, it is impossible to 
assess it's costs and benefits. So could a proponent of optional 
declarations please provide a more clear proposal?

Cheers,
Brian

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: /usr/bin/env python, force a version

2005-10-06 Thread Fredrik Lundh
"[EMAIL PROTECTED]" wrote:

> I've got a trouble, and i think that anybody there can help me
>
> I've got a python script which i distribute in somes packages for *nix.
> This script is full of python and need python 2.4 ! And i'd like to
> display a message when the user doesn't have a python2.4 version.

> I'd like to make my script (or a starter script)
> which will be able to detect all python versions of the machine. And
> run my script with the good one ; py2.4, or display a message to the
> user to say her it must install py2.4 ...

the approach used in bzr might work for you:

#
# application boot script

import os, sys

try:
version_info = sys.version_info
except AttributeError:
version_info = 1, 5 # 1.5 or older

REINVOKE = "__MYAPP_REINVOKE"
NEED_VERS = (2, 4)
KNOWN_PYTHONS = ('python2.4',)

if version_info < NEED_VERS:
if not os.environ.has_key(REINVOKE):
# mutating os.environ doesn't work in old Pythons
os.putenv(REINVOKE, "1")
for python in KNOWN_PYTHONS:
try:
os.execvp(python, [python] + sys.argv)
except OSError:
pass
print >>sys.stderr, "error: cannot find a suitable python interpreter"
print >>sys.stderr, "  (need %d.%d or later)" % NEED_VERS
sys.exit(1)

if hasattr(os, "unsetenv"):
os.unsetenv(REINVOKE)

#
# get things going!

import myapp
myapp.run()

# end of boot script

(the actual bzr source is shipped under the GPL, but 1) it's trivial, and 2) I 
contributed
the code in the first place, so I'd say it's safe to "steal this code" ;-)

 



-- 
http://mail.python.org/mailman/listinfo/python-list


Re: epydoc, variables and encoding

2005-10-06 Thread Michele Petrazzo
Kenneth Pronovici wrote:
>> I found a "problem" on epydoc. If I specify an encoding, epydoc not
>> find my global variables, and if I remove it, it work well.

<-cut->

> 
> No, it's not normal, and I'm fairly sure it's a bug.

<-cut->

> Otherwise, you can try applying the following patch:
> 

<-cut->

> Maybe Edward won't like this patch, but since he seems to be
> unreachable for the last six months , you'll have to settle for
> my less-than-educated guess at a fix. :)

I don't know why Edward won't like this parch :), in any case it work
well for my source.

> 
> KEN
> 

Thanks,
Michele
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: /usr/bin/env python, force a version

2005-10-06 Thread Roel Schroeven
Laszlo Zsolt Nagy wrote:
> [EMAIL PROTECTED] wrote:
> 
>> I've got a trouble, and i think that anybody there can help me
>>
>> I've got a python script which i distribute in somes packages for *nix.
>> This script is full of python and need python 2.4 ! And i'd like to
>> display a message when the user doesn't have a python2.4 version.
>>  
>>
 import sys
 sys.version
> '2.4.1 (#65, Mar 30 2005, 09:13:57) [MSC v.1310 32 bit (Intel)]'

Yes, but the problem is also that Debian (not only Sid, but also stable
and testing) has python 2.4 but it is not the default, i.e.
/usr/bin/python is a symlink to /usr/bin/python2.3 even if
/usr/bin/python2.4 is available to.

It would be nice if there was a general way to specify that a script
should be interpreted by python2.4, even if it is not the default, in a
way that works on all platforms. But I don't see how that should work.

-- 
If I have been able to see further, it was only because I stood
on the shoulders of giants.  -- Isaac Newton

Roel Schroeven
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Help with chaos math extensions.

2005-10-06 Thread Andrew Gwozdziewycz
On Oct 5, 2005, at 7:44 AM, Brandon K wrote:In case you missed it, I said I have windows XP.  Windows XP pre-compiled python binaries are built on VS .NET 2003.  In order to build extensions, you need the compiler the interpreter was built on, or at least that is what is reported to me by calling setup.py.  If I was using linux, which I currently am not, it'd be a different story.  Additionally, GCC isn't available for windows XP, only MinGW, the port, and I don't know that much about it to use it running on a Windows platform.  Furthermore, I was asking for help on an extension, not an economical question about my programming environment.Well, since I don't use Windows XP, I did not know this fact. I wasn't trying to offend you or argue with you, I was just flat out curious why you had to go out and buy Visual Studio.---Andrew Gwozdziewycz[EMAIL PROTECTED]http://ihadagreatview.orghttp://plasticandroid.org -- 
http://mail.python.org/mailman/listinfo/python-list

Re: Using command line args on Windows

2005-10-06 Thread Fredrik Lundh
"k8" wrote:

> I'm stuck on a Windows machine today and would love to fully play with
> and test a simple python script.  I want to be able to type "python
> myscript myarg" somewhere.  Is there anything out there to help me?

footnote: if you'd prefer to type "myscript myarg" instead, you might want
to check out this tool:

http://effbot.org/zone/exemaker.htm

 



-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Swig and pointers

2005-10-06 Thread Java and Swing
im sorry, why would it be md_ptr?  what is md_ptr?

i tried..
%include cpointer.i
%pointer_functions(MY_DIGIT, digit_ptr)

ptr = new_digit_ptr()
doIt("a message", ptr)
...doesnt work..still needs a DIGIT **

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Using command line args on Windows

2005-10-06 Thread Duncan Booth
Fredrik Lundh wrote:

>> I'm stuck on a Windows machine today and would love to fully play
>> with and test a simple python script.  I want to be able to type
>> "python myscript myarg" somewhere.  Is there anything out there to
>> help me? 
> 
> footnote: if you'd prefer to type "myscript myarg" instead, you might
> want to check out this tool:
> 
> http://effbot.org/zone/exemaker.htm

or even just do:

SET PATHEXT=.py;%PATHEXT%

and then "myscript myarg" will work for all scripts on your path without 
compiling (if you don't set PATHEXT then "myscript.py myarg" will still 
work, and tab completion means you don't generally need to type the .py for 
scripts in the current directory). 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: /usr/bin/env python, force a version

2005-10-06 Thread Laszlo Zsolt Nagy
Roel Schroeven wrote:

>Laszlo Zsolt Nagy wrote:
>  
>
>>[EMAIL PROTECTED] wrote:
>>
>>
>>
>>>I've got a trouble, and i think that anybody there can help me
>>>
>>>I've got a python script which i distribute in somes packages for *nix.
>>>This script is full of python and need python 2.4 ! And i'd like to
>>>display a message when the user doesn't have a python2.4 version.
>>> 
>>>
>>>  
>>>
>import sys
>sys.version
>  
>
>>'2.4.1 (#65, Mar 30 2005, 09:13:57) [MSC v.1310 32 bit (Intel)]'
>>
>>
>
>Yes, but the problem is also that Debian (not only Sid, but also stable
>and testing) has python 2.4 but it is not the default, i.e.
>/usr/bin/python is a symlink to /usr/bin/python2.3 even if
>/usr/bin/python2.4 is available to.
>  
>
Hmm.

Idea one:

Create a list of possible locations. First of all, use your PATH, and 
then add common locations:

['/bin','/usr/bin','/opt/bin','/usr/local/bin']  # etc.

Then use a list of the possible executable names:

['python','python2.3','python2.4'] # etc

Finally using these combinations, execute each executeable with

python -V

and examine its output. This may work, but I'm affraid there is no 
general solution.
The system administrator can install different python versions to 
virtually any location.
But I don't think you should be affraid of that. If a system admin 
installs different
versions into strange locations, then he will take the responsibility to 
fix python programs
that need a specific version. But in most cases, looking for a python 
executable
on your PATH should be enough; and it is the most I would expect from an 
application. :-)

Last idea:

- create a configuration file that resides beside your Python program
- take the path to the good executeable there
- if the program was started with the wrong version, but you have 
the path to the good one (from the config file), then re-execute
- otherwise print an error message telling the required version AND 
how the user can set it up in the config file

Third idea (for Windows only): read available versions from the 
registry. ;-)

Best,

  Les

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: updating local()

2005-10-06 Thread Flavio
Ok,

I got it!

Its vey insecure, and it is not guaranteed to work. Fine.

Now what would you do if you wanted to pass a lot of variables (like a
thousand) to a function and did not wanted the declare them in the
function header?

Flávio

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Extending Python

2005-10-06 Thread Magnus Lycka
Tuvas wrote:
> I am looking for a good tutorial on how to extend python with C code. I
> have an application built in C that I need to be able to use in Python.
> I have searched through various sources, starting of course with the
> Python site itself, and others, but I felt a bit lacking from the
> Python site, it seems it was only made for those who installed the
> source distribution, as for the other people... Anyways, thanks for the
> help!

There are several options. Besides the manual way described in the
Python docs and SWIG that Miki mentioned, there is for instance the
option of using Pyrex. See http://ldots.org/pyrex-guide/ and
http://www.cosc.canterbury.ac.nz/~greg/python/Pyrex/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: updating local()

2005-10-06 Thread Richard Brodie

"Flavio" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]

> Now what would you do if you wanted to pass a lot of variables (like a
> thousand) to a function and did not wanted the declare them in the
> function header?

I'd lie down until I felt better.


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python, Mysql, insert NULL

2005-10-06 Thread Thomas Bartkus
"Steve Holden" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> >
> If you don't understand parameterized SQL queries you would do well to
> refrain from offering database advice :-)

Did the poster ask a question about parameterized queries or server
security?

> Presumably you always check whether StrToConcatenateIntoSqlStatement
> contains no apostrophes before you actually construct the SQL?
>
> Can we say "SQL injection exploit"?

Not every query passes along public internet wires and all the guy asked for
was how to insert a Null.

But - I really do appreciate your concern :-)
Thomas Bartkus



-- 
http://mail.python.org/mailman/listinfo/python-list


Re: updating local()

2005-10-06 Thread Simon Brunning
On 6 Oct 2005 05:55:14 -0700, Flavio <[EMAIL PROTECTED]> wrote:
> Now what would you do if you wanted to pass a lot of variables (like a
> thousand) to a function and did not wanted the declare them in the
> function header?

I'd think twice. If on reflection I decided I really wanted to do it,
I'd pass them all in a dictionary.

--
Cheers,
Simon B,
[EMAIL PROTECTED],
http://www.brunningonline.net/simon/blog/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: updating local()

2005-10-06 Thread Diez B. Roggisch
Flavio wrote:
> Ok,
> 
> I got it!
> 
> Its vey insecure, and it is not guaranteed to work. Fine.
> 
> Now what would you do if you wanted to pass a lot of variables (like a
> thousand) to a function and did not wanted the declare them in the
> function header?

use a dict or list? This is almost certainly a design smell - and a 
pretty strong one, too.. Nobody is using so many variables and actually 
typing them - so there certainly is some naming scheme that could be 
used to access the values from a dict.

Or, to put it differently: show us the code that uses thousands of 
variables, and we show you how to improve that.

Diez
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Copy files to Linux server through ssh tunnel

2005-10-06 Thread Larry Bates
You might want to install copy of Cygwin on your Windows
box.  Then you can use scp or maybe rsync over ssh
to do the copying.  Works great for me.

-Larry Bates

[EMAIL PROTECTED] wrote:
> Hi !
> 
> I have some backup files on a server farm.
> I want to store these local backup files on a backup file server for
> "safety's snake".
> 
> These files are compressed zip files with 12 character length password.
> But my system admin asked me, how can I improve the safety of the copy
> operation, and the storing (now I use Samba share to store these files. I
> map the SMB share on the client, copy these files, and unmap SMB).
> 
> Then I thinking to ssh protocol to improve protection.
> 
> The backup script is a py script. I see that Winscp can copy files through
> ssh tunnel. Can I do it too ?
> How ? How to I do it in pythonic way ?
> 
> Please help me with some examples or urls or other infos !
> 
> Thanks * 1000:
> dd
> 
> 
> 
> 
> 
> 
> 
> --
> 1 Gbyte Ingyenes E-Mail Tárhely a MailPont-tól
> http://www.mailpont.hu/
> 

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: updating local()

2005-10-06 Thread Steve Holden
Richard Brodie wrote:
> "Flavio" <[EMAIL PROTECTED]> wrote in message
> news:[EMAIL PROTECTED]
> 
> 
>>Now what would you do if you wanted to pass a lot of variables (like a
>>thousand) to a function and did not wanted the declare them in the
>>function header?
> 
> 
> I'd lie down until I felt better.
> 
> 
Or alternatively put them in a 1,000-element list. Just as a matter of 
interest, what on *earth* is the use case for a function with a thousand 
arguments?

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006  www.python.org/pycon/

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Help with chaos math extensions.

2005-10-06 Thread Steve Holden
Brandon K wrote:
> In case you missed it, I said I have windows XP.  Windows XP 
> pre-compiled python binaries are built on VS .NET 2003.  In order to 
> build extensions, you need the compiler the interpreter was built on, or 
> at least that is what is reported to me by calling setup.py.  If I was 
> using linux, which I currently am not, it'd be a different story.  
> Additionally, GCC isn't available for windows XP, only MinGW, the port, 
> and I don't know that much about it to use it running on a Windows 
> platform.  Furthermore, I was asking for help on an extension, not an 
> economical question about my programming environment.
> 
> Thanks
> 
>>
>>On Oct 4, 2005, at 10:25 PM, Brandon Keown wrote:
>>
>>>   I have programmed a fractal generator (Julia Set/Mandelbrot Set) 
>>>in python in the past, and have had good success, but it would run so 
>>>slowly because of the overhead involved with the calculation.  I 
>>>recently purchased VS .NET 2003 (Win XP, precomp binary of python 
>>>2.4.2rc1) to make my own extensions.
>>
>>Why did you need to purchase anything when gcc is available for free?
>>
Since gcc isn't an option, the logical way to proceed would be to do 
what others have done and install the Microsoft Toolkit compiler, 
available from their web site for the outrageous price of nothing. I can 
vouch that it really does compile extensions for Python 2.4 on Windows, 
having done that myself.

See

   http://www.vrplumber.com/programming/mstoolkit/

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006  www.python.org/pycon/

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: "no variable or argument declarations are necessary."

2005-10-06 Thread Diez B. Roggisch
> 
> I can't help but feel that a lot of people have specific typechecking
> systems in mind and then conclude that the limits of such a symtem
> are inherent in typechecking itself.

I've been writing a type-checker for my diploma thesis for a functionnal 
programmming language. And it _is_ limited. The very subject of my work 
was to explore extended type-checking methods (so called 
multi-level-specifications),, which can be shwon to be NP-hard problems. 
Which naturally limits the domains they can be used to.

> IMO a good type system doesn't need to limit python in any way.

It has to. certainly. Take alone the list implementation - while 
typesystems as ML allow for generics (with much less typing overhead 
than JAVA), the list is always homogenous. Which python's aren't - and 
that a great thing(tm), even though ususally the contents of a list 
share some common behaviour. And that exactly is the key point here: in 
a statically typed world, that common behaviour must have been extracted 
and made explicit. Which is the cause for that notorious java io API. 
And, to extend the argument to ML-type type-checking, there you need a 
disjoint union of the possible types - _beforehand_, and the code 
dealing with it has to be aware of it.

In python OTH, I just pass objects I like into the list - if they 
behave, fine.

DIez
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: updating local()

2005-10-06 Thread Flavio
I wish all my problems involved just a couple of variables, but
unfortunately the real interesting problems tend to be complex...

As a last resort this problem could be solved by something like this:

def fun(**kw):
a = 100
for k,v in kw.items():
exec('%s = %s'%(k,v))
print locals()


>>> fun(**{'a':1,'b':2})
{'a': 1, 'k': 'b', 'b': 2, 'kw': {'a': 1, 'b': 2}, 'v': 2}

But that would be utterly stupid! So much for not being able to write
to locals()

any better Ideas?

-- 
http://mail.python.org/mailman/listinfo/python-list


Absolultely confused...

2005-10-06 Thread Jeremy Moles
So, here is my relevant code:

PyArg_ParseTuple(args, "O!", &PyType_vector3d, &arg1)

And here ismy error message:

argument 1 must be pylf.core.vector3d, not pylf.core.vector3d

I know PyType_vector3d "works" (as I can use them in the interpreter all
day long), and I know I'm passing a pylf.core.vector3d (well, apparently
not...)

I've spent hours and hours on this and I'm finally just giving up and
asking. I've tried everything to get my program to verify that arg1 is
really a PyType_vector3d, but to no avail.

If I take out the "!" in the format string and just use "O", I can at
least get past PyArg_ParseTuple. Then I try something like...

PyObject_TypeCheck(arg1, &PyType_vector3d)

Which also fails, but I know for a fact that arg1's PyObject_Repr is
what it should be. (pylf.core.vector3d)

I guess my question is: what in the world could be causing this to fail?
It seems like I'm just not able to use ParseType or BuildValue to create
objects of my own type.

I know I haven't provided a lot of information, but does anyone have any
ideas or where I should start looking?

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: "no variable or argument declarations are necessary."

2005-10-06 Thread Antoon Pardon
Op 2005-10-06, Diez B. Roggisch schreef <[EMAIL PROTECTED]>:
>> 
>> I can't help but feel that a lot of people have specific typechecking
>> systems in mind and then conclude that the limits of such a symtem
>> are inherent in typechecking itself.
>
> I've been writing a type-checker for my diploma thesis for a functionnal 
> programmming language. And it _is_ limited. The very subject of my work 
> was to explore extended type-checking methods (so called 
> multi-level-specifications),, which can be shwon to be NP-hard problems. 
> Which naturally limits the domains they can be used to.
>
>> IMO a good type system doesn't need to limit python in any way.
>
> It has to. certainly. Take alone the list implementation - while 
> typesystems as ML allow for generics (with much less typing overhead 
> than JAVA), the list is always homogenous. Which python's aren't - and 
> that a great thing(tm),

Suppose we have a typesystem which has the type ANY, which would mean
such an object could be any type. You could then have homogenous lists
in the sense that all elements should be of the same declared type and
at the same time mix all kind of type in a particular list, just
as python does.

So how would this limit python.

> even though ususally the contents of a list 
> share some common behaviour. And that exactly is the key point here: in 
> a statically typed world, that common behaviour must have been extracted 
> and made explicit.

Would my suggestion be classified as a statically typed world?

> Which is the cause for that notorious java io API. 
> And, to extend the argument to ML-type type-checking, there you need a 
> disjoint union of the possible types - _beforehand_, and the code 
> dealing with it has to be aware of it.
>
> In python OTH, I just pass objects I like into the list - if they 
> behave, fine.

But now we are no longer talking about how typechecking would limit
the language but about convenience for the user.

-- 
Antoon Pardon
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: updating local()

2005-10-06 Thread Flavio
Ok, its not thousands, but more like dozens of variables...
I am reading a large form from the web which returns a lot of values.
(I am Using cherrypy)

I know I could pass these variables around as:

def some_function(**variables):
...

some_function(**variables)

but its a pain in the neck to have to refer to them as
variables['whatever']...

dont you think? 

Flavio

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Class property

2005-10-06 Thread Laszlo Zsolt Nagy
Peter Otten wrote:

>Laszlo Zsolt Nagy wrote:
>
>  
>
>>I was trying for a while, but I could not implement a 'classproperty'
>>function. Is it possible at all?
>>
>>
>
>You could define a "normal" property in the metaclass:
>  
>
The only way I could do this is:

class MyXMetaClass(type):
_x = 0
def get_x(cls):
print "Getting x"
return cls._x
def set_x(cls,value):
cls._x = value
print "Set %s.x to %s" % (cls.__name__,value)
x = property(get_x,set_x)

class A(object):
__metaclass__ = MyXMetaClass
   
print A.x
A.x = 8


Results in:

Getting x
0
Set A.x to 8

But of course this is bad because the class attribute is not stored in 
the class. I feel it should be.
Suppose we want to create a class property, and a class attribute; and 
we would like the property get/set methods to use the values of the 
class attributes.
A real example would be a class that keeps track of its direct and 
subclassed instances:

class A(object):
cnt = 0
a_cnt = 0
def __init__(self):
A.cnt += 1
if self.__class__ is A:
A.a_cnt += 1
   
class B(A):
pass
   
print A.cnt,A.a_cnt # 0,0
b = B()
print A.cnt,A.a_cnt # 1,0
a = A()
print A.cnt,A.a_cnt # 2,1

But then, I may want to create read-only class property that returns the 
cnt/a_cnt ratio.
This now cannot be implemented with a metaclass, because the metaclass 
cannot operate on the class attributes:

class A(object):
cnt = 0
a_cnt = 0
ratio = a_class_property_that_returns_the_cnt_per_a_cnt_ratio() # 
def __init__(self):
A.cnt += 1
if self.__class__ is A:
A.a_cnt += 1

Any ideas?

   Les



-- 
http://mail.python.org/mailman/listinfo/python-list


Re: New Python book

2005-10-06 Thread Scott David Daniels
Jeremy Jones wrote (about Magnus Lie Hetland's
 _Beginning Python: From Novice to Professional_):
> ...  this would probably also be an excellent educational resource 
> for teachers in a classroom setting teaching students Python.  I would 
> be interested to hear some teachers' opinion on that to see if 
> that's a correct assessment

You could ask over on comp.lang.python.education (on
Gmane as comp.python.education).

-- 
-Scott David Daniels
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Help with chaos math extensions.

2005-10-06 Thread Brandon K
Well, I didn't buy it JUST to compile python extensions, I'm looking to 
write C++ apps as well, I just use python for a lot of math and science 
simulations, and I got VS .NET at heavy discount since I'm a student.
> Brandon K wrote:
>> In case you missed it, I said I have windows XP.  Windows XP 
>> pre-compiled python binaries are built on VS .NET 2003.  In order to 
>> build extensions, you need the compiler the interpreter was built on, 
>> or at least that is what is reported to me by calling setup.py.  If I 
>> was using linux, which I currently am not, it'd be a different story.  
>> Additionally, GCC isn't available for windows XP, only MinGW, the 
>> port, and I don't know that much about it to use it running on a 
>> Windows platform.  Furthermore, I was asking for help on an extension, 
>> not an economical question about my programming environment.
>>
>> Thanks
>>
>>>
>>> On Oct 4, 2005, at 10:25 PM, Brandon Keown wrote:
>>>
   I have programmed a fractal generator (Julia Set/Mandelbrot Set) 
 in python in the past, and have had good success, but it would run 
 so slowly because of the overhead involved with the calculation.  I 
 recently purchased VS .NET 2003 (Win XP, precomp binary of python 
 2.4.2rc1) to make my own extensions.
>>>
>>> Why did you need to purchase anything when gcc is available for free?
>>>
> Since gcc isn't an option, the logical way to proceed would be to do 
> what others have done and install the Microsoft Toolkit compiler, 
> available from their web site for the outrageous price of nothing. I can 
> vouch that it really does compile extensions for Python 2.4 on Windows, 
> having done that myself.
> 
> See
> 
>   http://www.vrplumber.com/programming/mstoolkit/
> 
> regards
>  Steve


== Posted via Newsgroups.com - Usenet Access to over 100,000 Newsgroups 
==
Get Anonymous, Uncensored, Access to West and East Coast Server Farms! 
== Highest Retention and Completion Rates! HTTP://WWW.NEWSGROUPS.COM ==


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: /usr/bin/env python, force a version

2005-10-06 Thread Michael Ekstrand
On Thursday 06 October 2005 06:25, [EMAIL PROTECTED] wrote:
> I hope you understand my needs. Is there a python/bash mechanism to
> override the default python version of the system ...  and run the
> script with any version of python (but the most recent) ?
> or can you explain me how to do that ? the simplest way ?

This solution makes a few assumptions... but it should work in the 
majority of cases.

The principle is that Python is, in my experience, *usually* installed 
as python2.4 or whatever - even ./configure && make && make install in 
the tarball makes python a symbolic link to a python2.4 executable. 
Assuming that this is the case, and that python2.4 will never be any 
other version of Python:

#!/bin/sh

APPPATH=/path/to/app
PYTHON=`which python2.4`

if [ $? != 0 ]; then
echo "This program requires Python 2.4 to be installed." >/dev/stderr
exit 1
fi

"$PYTHON" "$APPATH" "$@"

Problems: Requires Python 2.4 to be installed as python2.4, and doesn't 
have upward compatibility (i.e. 2.5). But it's at least as good as 
#!/usr/bin/env python2.4, and it gives a clean error message.

-Michael
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: py2exe has a new maintainer

2005-10-06 Thread Thomas Heller
"Jimmy Retzlaff" <[EMAIL PROTECTED]> writes:

> I am taking over the maintenance and support of py2exe from Thomas
> Heller. As he announced a few weeks ago he is looking to focus on other
> things. py2exe has been very useful to me over the years and I look
> forward to keeping it every bit as useful in the future.

Jimmy, I'm very happy that you take over the py2exe package maintainace
and wish you all good luck with it.  Open source how it should work!

Thanks again,

Thomas
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Absolultely confused...

2005-10-06 Thread Brandon K

> If I take out the "!" in the format string and just use "O", I can at
> least get past PyArg_ParseTuple. 

Is this a compile-time error? Or a runtime error?



== Posted via Newsgroups.com - Usenet Access to over 100,000 Newsgroups 
==
Get Anonymous, Uncensored, Access to West and East Coast Server Farms! 
== Highest Retention and Completion Rates! HTTP://WWW.NEWSGROUPS.COM ==


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: check html file size

2005-10-06 Thread Richard Gration
On Wed, 05 Oct 2005 20:39:18 -0400, Sherm Pendley wrote:

> Richard Gration <[EMAIL PROTECTED]> writes:
> 
>> Are you fucking seriously fucking expecting some fucking moron to
>> translate your tech geeking fucking code moronicity? Fucking try writing
>> it fucking properly in fucking Perl first.
> 
> Good fucking job! That's the funniest fucking response I've ever fucking seen
> to Xah's fucking moronistic fucking nonsense.

Thanks, Sherm. I knew someone would get it. I think Bear and Ulrich
haven't yet been exposed to Xah "in full effect" ;-) They're probably
denizens of the Scheme group which seems to be a new entry on Xah's "this
newsgroup needs spamming" list ;-)

> Lenny Bruce would be so fucking proud.

LOL
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: updating local()

2005-10-06 Thread Simon Brunning
On 6 Oct 2005 07:04:08 -0700, Flavio <[EMAIL PROTECTED]> wrote:
> I know I could pass these variables around as:
>
> def some_function(**variables):
> ...
>
> some_function(**variables)
>
> but its a pain in the neck to have to refer to them as
> variables['whatever']...
>
> dont you think?

Err, no, not really. ;-)

If you'd prfefer to access them like this:

variables.whatever

Check out the Bunch class here -
.

--
Cheers,
Simon B,
[EMAIL PROTECTED],
http://www.brunningonline.net/simon/blog/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Absolultely confused...

2005-10-06 Thread Jeremy Moles
All of these are runtime errors. Using GCC4 and compiling perfectly with
-Wall.

On Thu, 2005-10-06 at 09:12 -0500, Brandon K wrote:
> > If I take out the "!" in the format string and just use "O", I can at
> > least get past PyArg_ParseTuple. 
> 
> Is this a compile-time error? Or a runtime error?
> 
> 
> 
> == Posted via Newsgroups.com - Usenet Access to over 100,000 Newsgroups 
> ==
> Get Anonymous, Uncensored, Access to West and East Coast Server Farms! 
> == Highest Retention and Completion Rates! HTTP://WWW.NEWSGROUPS.COM 
> ==
> 
> 

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to prevent logging warning?

2005-10-06 Thread Thomas Heller
"Vinay Sajip" <[EMAIL PROTECTED]> writes:

> Thomas Heller wrote:
>
>> I get the behaviour that I want when I add a 'NULL' handler in the
>> library, but is this really how logging is intended to be used?
>>
>
> The reason for the one-off message is that without it, a
> misconfiguration or a failure to configure any handlers is notified to
> a user (who is possibly not used to the logging package). I'm not sure
> which is more annoying - a one-off message which occurs when no
> handlers are configured and yet events are logged, or complete silence
> from logging when something is misconfigured, and not giving any
> feedback on what's wrong? (It's a rhetorical question - the answer is
> of course quite subjective).

I do *not* think 'no handler' is a misconfiguration. Is it possible to
differentiate between a misconfiguration and 'no configuration'?

> Certainly, I could change things so that e.g. the error is suppressed
> when logging.raiseExceptions is set to 0 (typically for production
> use).

That would be fine.  But there are also other ways - you could, for
example, print the warning only when __debug__ is False.  And you could
use the warnings module instead of blindly printing to stderr, this way
it could also be filtered out.

BTW: Since I have your attention now, is the graphical utility to
configure the logging.conf file still available somewhere, and
compatible with the current logging package (with 'current' I mean
the one included with Python 2.3.5)?

Thomas
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: updating local()

2005-10-06 Thread Robert Kern
Flavio wrote:
> Ok, its not thousands, but more like dozens of variables...
> I am reading a large form from the web which returns a lot of values.
> (I am Using cherrypy)
> 
> I know I could pass these variables around as:
> 
> def some_function(**variables):
> ...
> 
> some_function(**variables)
> 
> but its a pain in the neck to have to refer to them as
> variables['whatever']...
> 
> dont you think? 

Use a Bunch.

class Bunch(dict):
def __init__(self, *args, **kwds):
dict.__init__(self, *args, **kwds)
self.__dict__ = self

-- 
Robert Kern
[EMAIL PROTECTED]

"In the fields of hell where the grass grows high
 Are the graves of dreams allowed to die."
  -- Richard Harter

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Absolultely confused...

2005-10-06 Thread Thomas Heller
Jeremy Moles <[EMAIL PROTECTED]> writes:

> So, here is my relevant code:
>
>   PyArg_ParseTuple(args, "O!", &PyType_vector3d, &arg1)
>
> And here ismy error message:
>
>   argument 1 must be pylf.core.vector3d, not pylf.core.vector3d
>
> I know PyType_vector3d "works" (as I can use them in the interpreter all
> day long), and I know I'm passing a pylf.core.vector3d (well, apparently
> not...)
>
> I've spent hours and hours on this and I'm finally just giving up and
> asking. I've tried everything to get my program to verify that arg1 is
> really a PyType_vector3d, but to no avail.
>
> If I take out the "!" in the format string and just use "O", I can at
> least get past PyArg_ParseTuple. Then I try something like...
>
>   PyObject_TypeCheck(arg1, &PyType_vector3d)
>
> Which also fails, but I know for a fact that arg1's PyObject_Repr is
> what it should be. (pylf.core.vector3d)
>
> I guess my question is: what in the world could be causing this to fail?
> It seems like I'm just not able to use ParseType or BuildValue to create
> objects of my own type.
>
> I know I haven't provided a lot of information, but does anyone have any
> ideas or where I should start looking?

Can it be that you have TWO instances of the pylf.core.vector3d object?
Debugging should reveal it...

Thomas
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Simple prototype text editor in python

2005-10-06 Thread thakadu
Hi Viktor

At the moment I dont have any web site where I can
upload it. Do you or anyone have any suggestions or
know of any web sites where one can post python code?
If not please email me and I will send you the code by email.

Regarding the license I have not yet decided what type
of license (if any, since its very few lines of code)  but probably
will be GPL or BSD style. I have no former experience in
licensing code so any suggestions will be welcome there as well.
(For one, do you know if simply stating somewhere in the
code "This is licensed under blah blah" is sufficient
to consider the code licensed?)

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: "no variable or argument declarations are necessary."

2005-10-06 Thread Diez B. Roggisch
> Suppose we have a typesystem which has the type ANY, which would mean
> such an object could be any type. You could then have homogenous lists
> in the sense that all elements should be of the same declared type and
> at the same time mix all kind of type in a particular list, just
> as python does.

The you have JAVA Object or C void*. Which cause all kinds of runtime 
troubles because they essentially circumvene the typechecking!

> 
> So how would this limit python.

The limitation is that in static languages I must _know_ what type to 
cast such an ANY, before calling anything on it. Otherwise its useless.

>>even though ususally the contents of a list 
>>share some common behaviour. And that exactly is the key point here: in 
>>a statically typed world, that common behaviour must have been extracted 
>>and made explicit.
> 
> 
> Would my suggestion be classified as a statically typed world?

See above.

> 
> 
>>Which is the cause for that notorious java io API. 
>>And, to extend the argument to ML-type type-checking, there you need a 
>>disjoint union of the possible types - _beforehand_, and the code 
>>dealing with it has to be aware of it.
>>
>>In python OTH, I just pass objects I like into the list - if they 
>>behave, fine.
> 
> 
> But now we are no longer talking about how typechecking would limit
> the language but about convenience for the user.

That's dialectics. Limits in the language limit the user and make things 
inconvenient.

Diez
-- 
http://mail.python.org/mailman/listinfo/python-list


So far

2005-10-06 Thread CppNewB
I am absolutely loving my experience with Python.  Even vs. Ruby, the syntax 
feels very clean with an emphasis on simplification.

My only complaint is that there doesn't appear to be a great commercial IDE 
for the language.  I've tried Komodo, etc and they are nice applications, 
but they don't feel like they give me the "power" like a Visual Studio or 
Delphi (I wish I could articulate better the differences).Finding a 
descent GUI builder has been a challenge as well.  Most of them have support 
for Dialogs, but what about more complex UI's?  I may need a resizable frame 
within a resizable frame? I haven''t found a GUI builder with a great feel 
yet.

Other than that, my experience has been wonderful.  Even after my 
complaints, I plan on sticking with Python for a while. 


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: So far

2005-10-06 Thread UrsusMaximus
Try PythonCard

Ron Stephens
Python Learning Center
a prententious name for a nice hobbyist resource
www.awaretek.com/plf.html

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: So far

2005-10-06 Thread UrsusMaximus
Try PythonCard

Ron Stephens
Python Learning Center
a prententious name for a nice hobbyist resource
www.awaretek.com/plf.html

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: updating local()

2005-10-06 Thread El Pitonero
Flavio wrote:
> I wish all my problems involved just a couple of variables, but
> unfortunately the real interesting problems tend to be complex...
>
> def fun(**kw):
> a = 100
> for k,v in kw.items():
> exec('%s = %s'%(k,v))
> print locals()
>
>
> >>> fun(**{'a':1,'b':2})
> {'a': 1, 'k': 'b', 'b': 2, 'kw': {'a': 1, 'b': 2}, 'v': 2}
>
> any better Ideas?

Actually, your solution is not bad. Some potential problems are: (1)
unintentional name collisions with other variables, including
globals/builtins, (2) it's easy to unpack variables into locals(), but
not easy to pack them back, since locals() are often contaminated with
extra auxiliary variables.

Your problem happens often in the field of math formulas/equations.

I remember similar problem happens in C++, too. When one has a function
with a long list of parameters, in C++ one may find oneself updating
the funtion header/prototype all the time, which is very tiresome and
error-prone.

When you have complicated list of arguments to pass, it's better to put
them into a structure/object. This way, the function header/prototype
will remain the same, and you only need to change the declaration of
the object.

The parameter object(s) could be called:

- request and response, if input and output are separated
- param
- workspace, session, etc.

so, your function call would look like

class Param: pass
...
def f(p):
result = p.x + p.y
return result
...
p=Param()
p.x = 3
p.y = 4
result = f(p)

Now, you may not like the extra dots in the line:

result = p.x + p.y

My experience is: it's not that bad to have names with extra dots. I
know it's annoying, but not a total disaster. Plus, once you start to
use OOP, it makes your code more organized. It has its benefits. For
instance, very often your models/formulas have several versions. Using
OOP's class hierarchy inheritance mechanism allows you to try out
different versions or different ideas much more easily, and you can
roll back the changes more easily, too (instead of commenting out code
lines all over places.) If you do decide to go the route of OOP, the
lines:

p.x = 3
p.y = 4
p.z = 5

can be replaced by something like:

calculation_engine.set(x=3, y=4)
calculation_engine.set(z=5)

--

The longer answer is: if you need complex formula evaluations, Python
is probably not the language to use. For speed and memory usage issues,
C++ is probably what you need. You can hookup your C++ program to
Python in various ways, but packing/unpacking variables seems
unavoidable. And even in C++ (where object attributes don't have the
dots inside the object's own methods), I still often end up using a lot
of dotted names for attributes from other objects.

If the problem is complex, then it's complex. I know you have your
equations, but you have to decide for yourself: is it better to do all
the packing/unpacking, or is it better to change your equations to use
the dotted names? There is no right or wrong answer, it all depends on
your particular situation.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Absolultely confused...

2005-10-06 Thread Jeremy Moles
Thanks for the reply. :)

I may be missing something critical here, but I don't exactly grok what
you're saying; how is it even possible to have two instances of
PyType_vector3d? It is (like all the examples show and all the extension
modules I've done in the past) a static structure declared and assigned
to all at once, only once.

Am I misunderstanding the point? :)

/me ducks

On Thu, 2005-10-06 at 16:26 +0200, Thomas Heller wrote:
> Jeremy Moles <[EMAIL PROTECTED]> writes:
> 
> > So, here is my relevant code:
> >
> > PyArg_ParseTuple(args, "O!", &PyType_vector3d, &arg1)
> >
> > And here ismy error message:
> >
> > argument 1 must be pylf.core.vector3d, not pylf.core.vector3d
> >
> > I know PyType_vector3d "works" (as I can use them in the interpreter all
> > day long), and I know I'm passing a pylf.core.vector3d (well, apparently
> > not...)
> >
> > I've spent hours and hours on this and I'm finally just giving up and
> > asking. I've tried everything to get my program to verify that arg1 is
> > really a PyType_vector3d, but to no avail.
> >
> > If I take out the "!" in the format string and just use "O", I can at
> > least get past PyArg_ParseTuple. Then I try something like...
> >
> > PyObject_TypeCheck(arg1, &PyType_vector3d)
> >
> > Which also fails, but I know for a fact that arg1's PyObject_Repr is
> > what it should be. (pylf.core.vector3d)
> >
> > I guess my question is: what in the world could be causing this to fail?
> > It seems like I'm just not able to use ParseType or BuildValue to create
> > objects of my own type.
> >
> > I know I haven't provided a lot of information, but does anyone have any
> > ideas or where I should start looking?
> 
> Can it be that you have TWO instances of the pylf.core.vector3d object?
> Debugging should reveal it...
> 
> Thomas

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Absolultely confused...

2005-10-06 Thread Thomas Heller
Jeremy Moles <[EMAIL PROTECTED]> writes:

> Thanks for the reply. :)
>
> I may be missing something critical here, but I don't exactly grok what
> you're saying; how is it even possible to have two instances of
> PyType_vector3d? It is (like all the examples show and all the extension
> modules I've done in the past) a static structure declared and assigned
> to all at once, only once.
>
> Am I misunderstanding the point? :)
>
> /me ducks
>
> On Thu, 2005-10-06 at 16:26 +0200, Thomas Heller wrote:
>> Jeremy Moles <[EMAIL PROTECTED]> writes:
>> 
>> > So, here is my relevant code:
>> >
>> >PyArg_ParseTuple(args, "O!", &PyType_vector3d, &arg1)
>> >
>> > And here ismy error message:
>> >
>> >argument 1 must be pylf.core.vector3d, not pylf.core.vector3d
>> >

The only reason that I can think of for this error message is that the
type of the argument is something that has a repr of
'pylf.core.vector3d', but the type object is not the same as your
'PyType_vector3d' pointer.  As I said, use a source debugger or some
other way to find out, or use a debug build of Python and step through
the PyArg_ParseTuple code to find out why the call fails.

Thomas
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Simple prototype text editor in python

2005-10-06 Thread Robert Kern
thakadu wrote:
> Hi Viktor
> 
> At the moment I dont have any web site where I can
> upload it. Do you or anyone have any suggestions or
> know of any web sites where one can post python code?
> If not please email me and I will send you the code by email.

If you package it with distutils, then you can upload the source
distribution automatically to PyPI:

  http://python.org/pypi

> Regarding the license I have not yet decided what type
> of license (if any, since its very few lines of code)  but probably
> will be GPL or BSD style. I have no former experience in
> licensing code so any suggestions will be welcome there as well.
> (For one, do you know if simply stating somewhere in the
> code "This is licensed under blah blah" is sufficient
> to consider the code licensed?)

Perhaps, but you really should include the full license text somewhere.
Since your code is so short, then I highly recommend using a short,
permissive license. It does no one any good to attach a license that's
longer than the program itself.

-- 
Robert Kern
[EMAIL PROTECTED]

"In the fields of hell where the grass grows high
 Are the graves of dreams allowed to die."
  -- Richard Harter

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Absolultely confused...

2005-10-06 Thread Daniel Dittmar
Jeremy Moles wrote:
> So, here is my relevant code:
> 
>   PyArg_ParseTuple(args, "O!", &PyType_vector3d, &arg1)
> 
> And here ismy error message:
> 
>   argument 1 must be pylf.core.vector3d, not pylf.core.vector3d
> 

It looks as if two PyType_vector3d exist in your system
- the one that created the object passed to your routine
- the one in your extension code

As PyType_vector3d probably comes from a shared object/DLL
- does your code accesses really the same shared object that is also 
loaded by the Python interpreter? It could be that you linked with a 
specific file, but Python loads something different from $PYTHONPATH
- on Windows, you couldn't simply import a variable from a DLL, you had 
to call a special routine to get the pointer

One possible portable solution: in your module initialization
- import pylf.core
- create an object of type vector3d
- use your knowledge about the inner structure of Python objects and get 
the pointer to the PyType from the object
- store it in a module static variable TypeVector3D
- pass that variable to PyArg_ParseTuple

Browse the Python Extension API, maybe partts or all of this are already 
available.

There's still a problem left when pylf.core gets reloaded (rare, but 
possible). I assume the shared object also gets reloaded, which means 
that the type objects gets loaded to a new address and PyArg_ParseTuple 
will complain again. I'm not sure if there is a solution to this, 
because there still could be objects create from the old module.

Maybe you should just check the type yourself by comparing the class 
names buried in the PyType. You could cache one or two type pointers to 
speed this up.

Daniel
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Convert hex to string

2005-10-06 Thread Magnus Lycka
Java and Swing wrote:
> I have some output stored in a string that looks like..
> 
> 
>>>x
> 
> '\x01\xee\x1eo\xc3+\x8b\x83\xfad\xf6E\xaa\x0ea/I\x96\x83\xf5G\xa3\rQ\xfcH\xee\r'
> 
> 
> According to, http://docs.python.org/lib/typesseq-strings.html, this is
> "Unsigned Hexidecimal (lowercase)".  How can I get this into normal
> Ascii so that I can read it?

What did you expect this string to print? Where did it come from?
Viewed as ASCII it's mainly non-printables, with o, +, d, E, a/I,
G, Q and H stuffed in, but I'm pretty sure it isn't 8 bit text
in any normal encoding. The only reason to suspect that this might
be text after all, is that it ends with a carriage return.

Converting your string to numbers, we get...
1 238 30 111(o) 195 43(+) 139 131 250 100(d) 246 69(E) 170 14 97(a)
47(/) 73(I) 150 131 245 71(G) 163 13 81 (Q) 252 72(H) 238 13.

You can find the definition of ASCII via Google.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Absolultely confused...

2005-10-06 Thread Fredrik Lundh
Jeremy Moles wrote:

> So, here is my relevant code:
>
> PyArg_ParseTuple(args, "O!", &PyType_vector3d, &arg1)
>
> And here ismy error message:
>
> argument 1 must be pylf.core.vector3d, not pylf.core.vector3d

try adding

printf("%p %p\n", &PyType_vector3d, arg1->ob_type);

before the parsetuple statement.

> I guess my question is: what in the world could be causing this to fail?

multiple instances of the type object.





-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Absolultely confused...

2005-10-06 Thread Jeremy Moles
Well, there's certainly no doubting that all of you are right. I guess
now I need to track down how this is happening and either fix it or
understand it so that I can explain why I'm having to work around it. :)

Many, many thanks. :)

On Thu, 2005-10-06 at 16:48 +0200, Daniel Dittmar wrote:
> Jeremy Moles wrote:
> > So, here is my relevant code:
> > 
> > PyArg_ParseTuple(args, "O!", &PyType_vector3d, &arg1)
> > 
> > And here ismy error message:
> > 
> > argument 1 must be pylf.core.vector3d, not pylf.core.vector3d
> > 
> 
> It looks as if two PyType_vector3d exist in your system
> - the one that created the object passed to your routine
> - the one in your extension code
> 
> As PyType_vector3d probably comes from a shared object/DLL
> - does your code accesses really the same shared object that is also 
> loaded by the Python interpreter? It could be that you linked with a 
> specific file, but Python loads something different from $PYTHONPATH
> - on Windows, you couldn't simply import a variable from a DLL, you had 
> to call a special routine to get the pointer
> 
> One possible portable solution: in your module initialization
> - import pylf.core
> - create an object of type vector3d
> - use your knowledge about the inner structure of Python objects and get 
> the pointer to the PyType from the object
> - store it in a module static variable TypeVector3D
> - pass that variable to PyArg_ParseTuple
> 
> Browse the Python Extension API, maybe partts or all of this are already 
> available.
> 
> There's still a problem left when pylf.core gets reloaded (rare, but 
> possible). I assume the shared object also gets reloaded, which means 
> that the type objects gets loaded to a new address and PyArg_ParseTuple 
> will complain again. I'm not sure if there is a solution to this, 
> because there still could be objects create from the old module.
> 
> Maybe you should just check the type yourself by comparing the class 
> names buried in the PyType. You could cache one or two type pointers to 
> speed this up.
> 
> Daniel

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: So far

2005-10-06 Thread Benji York
CppNewB wrote:
> Most of them have support for Dialogs, but what about more complex
> UI's?  I may need a resizable frame within a resizable frame? I
> haven''t found a GUI builder with a great feel yet.

I *highly* recommend wxDesigner.  I've used it extensively.  It's cheap 
and has a demo version you can download (the demo can't save your 
designs, but can generate code so you can try it out).
--
Benji York
-- 
http://mail.python.org/mailman/listinfo/python-list


shelve object back to dictionary

2005-10-06 Thread Ryan Krauss
Is there an easy way to convert a shelved object back to a dictionary?
 When I save a dictionary using shelve and then load it in a later
session, I have an object whose property names are the keys of the
dictionary used as an input to shelve.  For example, instead of
user['name'] I have user.name.  I would prefer to have the scripts I
write to analyze the saved data have a similar syntax to the ones I
used to create it, so I would rather deal with a dictionary after I
load the shelved data.

Ryan
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: "no variable or argument declarations are necessary."

2005-10-06 Thread Pierre Barbier de Reuille
Mike Meyer a écrit :
> Antoon Pardon <[EMAIL PROTECTED]> writes:
> 
>>Op 2005-10-03, Steven D'Aprano schreef <[EMAIL PROTECTED]>:
>>
>>>On Mon, 03 Oct 2005 13:58:33 +, Antoon Pardon wrote:
>>
>>Declarations also allow easier writable closures. Since the declaration
>>happens at a certain scope, the run time can easily find the correct
>>scope when a variable is rebound.
> 
> 
> If it happens at runtime, then you can do it without declarations:
> they're gone by then. Come to think of it, most functional languages -
> which are the languages that make the heaviest use of closures - don't
> require variable declarations.

Well, can you give a single example of such language ? Because all the
functionnal language I know but one do need variable declaration : lisp,
scheme, ocaml, haskell do need variable declaration ! Erlang do not ...

> 
> 
[...]
> 
> 
> Only in a few cases. Type inferencing is a well-understood
> technology, and will produce code as efficient as a statically type
> language in most cases.
> 

Type inferencing only works for statically typed languages AFAIK ! In a
dynamically typed languages, typing a variable is simply impossible as
any function may return a value of any type !

> 
>>I think language matters shouldn't be setlled by personal preferences.
> 
> 
> I have to agree with that. For whether or not a feature should be
> included, there should either be a solid reason dealing with the
> functionality of the language - meaning you should have a set of use
> cases showing what a feature enables in the language that couldn't be
> done at all, or could only be done clumsily, without the feature.

Wrong argument ... with that kind of things, you would just stick with
plain Turing machine ... every single computation can be done with it !

> 
> Except declarations don't add functionality to the language. They
> effect the programing process. And we have conflicting claims about
> whether that's a good effect or not, all apparently based on nothing
> solider than personal experience. Which means the arguments are just
> personal preferences.
> 

Well, so why not *allow* for variable declaration ? Languages like Perl
does that successfully ... you don't like : you don't do ! you like :
you do ! A simple option at the beginning of the file tell the compilor
if variable declaration is mandatory or not !

> Until someone does the research to provide hard evidence one way or
> another, that's all we've got to work with. Which means that languages
> should exist both with and with those features, and if one sides
> experiences generalize to the population at large, they alternative
> languages will die out. Which hasn't happened yet.
> 
> 
>>But we should decide what language features are usefull and which are
>>not by what some individual can or can't live without.
> 
> 
> Um - that's just personal preference (though I may have misparsed your
> sentence). What one person can't live without, another may not be able
> to live with. All that means is that they aren't likely to be happy
> with the same programming language. Which is fine - just as no
> programming language can do everything, no programming language can
> please everyone.
> 
> Antoon, at a guess I'd say that Python is the first time you've
> encountered a dynamnic language. Being "horrified" at not having
> variable declarations, which is a standard feature of such languages
> dating back to the 1950s, is one such indication.

Dynamic language and variable declaration are non-related issues ! You
can have statically-typed language without variable declaration (i.e.
BASIC) and dynamically-typed language with (i.e. Lisp) ! Please, when
you says something about languages, at least give 1 name of language
asserting what you're saying !

> Dynamic languages tend to express a much wider range of programming
> paradigms than languages that are designed to be statically
> compiled. Some of these paradigms do away with - or relegate to the
> level of "ugly performance hack" - features that someone only
> experienced with something like Pascal would consider
> essential. Assignment statements are a good example of that.

Well, could you be more specific once more ? I can't that many paradigm
only available on dynamically typed languages ... beside duck-typing
(which is basically a synonym for dynamically-typed)

> Given these kinds of differences, prior experience is *not* a valid
> reason for thinking that some difference must be wrong. Until you have
> experience with the language in question, you can't really decide that
> some feature being missing is intolerable. You're in the same position
> as the guy who told me that a language without a goto would be
> unusable based on his experience with old BASIC, FORTRAN IV and
> assembler.

After more than two years of Python programming, I still fill the need
for variable declarations. It would remove tons of bugs for little works
and would also clarify the scope of any single variable.

> P

Re: So far

2005-10-06 Thread Christophe
CppNewB a écrit :
> I am absolutely loving my experience with Python.  Even vs. Ruby, the syntax 
> feels very clean with an emphasis on simplification.
> 
> My only complaint is that there doesn't appear to be a great commercial IDE 
> for the language.  I've tried Komodo, etc and they are nice applications, 
> but they don't feel like they give me the "power" like a Visual Studio or 
> Delphi (I wish I could articulate better the differences).Finding a 
> descent GUI builder has been a challenge as well.  Most of them have support 
> for Dialogs, but what about more complex UI's?  I may need a resizable frame 
> within a resizable frame? I haven''t found a GUI builder with a great feel 
> yet.
> 
> Other than that, my experience has been wonderful.  Even after my 
> complaints, I plan on sticking with Python for a while. 

Try PyQT with eric3 as an IDE.

http://www.die-offenbachs.de/detlev/eric3.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: updating local()

2005-10-06 Thread Grant Edwards
On 2005-10-06, Flavio <[EMAIL PROTECTED]> wrote:
> Ok,
>
> I got it!
>
> Its vey insecure, and it is not guaranteed to work. Fine.
>
> Now what would you do if you wanted to pass a lot of variables (like a
> thousand) to a function and did not wanted the declare them in the
> function header?

Pass them in a dictionary or tuple or list or object with
attributes.

-- 
Grant Edwards   grante Yow!  Am I SHOPLIFTING?
  at   
   visi.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Can Python replace TCL/Expect

2005-10-06 Thread Jorgen Grahn
On Thu, 06 Oct 2005 11:08:09 GMT, Cameron Laird <[EMAIL PROTECTED]> wrote:
> In article <[EMAIL PROTECTED]>,
> Robert Kern  <[EMAIL PROTECTED]> wrote:
>>[EMAIL PROTECTED] wrote:
>>> Hi
>>> 
>>> I'm learning Python. I don't know whether Python can do something like
>>> Expect can do. If yes, please show me how to do it.
...
> 2.  While Pexpect indeed "can do something like Expect", 
> it does NOT have all the facilities and polish of the
> latter.
> 3.  But very, VERY few of Expect's users are aware of more
> than a handful of Expect's functions, let alone use them,
> so it's fair to say that Pexpect does everything Expect
> does, within the realm of ordinary use.

It depends. I do not feel /that/ advanced, but I've been bitten by pexpect's
limitations several times in several places.

... which puts me in a weird position ;-) I /loathe/ the Tcl language, but I
have to admit that its expect functionality is far superior to Python's.

/Jorgen

-- 
  // Jorgen GrahnR'lyeh wgah'nagl fhtagn!
-- 
http://mail.python.org/mailman/listinfo/python-list


Newbie ? MS Sql update of record

2005-10-06 Thread len
I have created a python program that takes a flat file and changes some
of the data and create a new flat file with the changes.  Part of this
process requires that I try to find a particular model car in an MS Sql
table.  This part of the program is now working great.

It has come to my attention that some of the information in the flat
file could be used to update our information in the MS Sql table that I
currently run the query on.  Basicly I create a recordset of vehicles
from the MS Sql table based on vehicle year and make and once I have
this recordset I run it through logic which does a reqular expression
compare on the vehicle VIN no to the
VIN number in the table to get a match.  I would like to update this
record in the table with info. in the flat file.  I believe there
should be some way to update the fields in this record of the recordset
and then update the table.  I am not an sql expert and would appreciate
someone pointing me in the right direction.  Contained below is a
listing of my code;

# The following code creates a connection object,
# assigns the connection string, opens the
# connection object, and then verifies a good
# connection.

oConn = Dispatch('ADODB.Connection')

oConn.ConnectionString = "Provider=SQLOLEDB.1;" +\
 "Data Source=uicesv05;" +\
 "uid=aiis;" +\
 "pwd=aiis;" +\
 "database=auto_mo_001"

oConn.Open()
if oConn.State == adStateOpen:
print "Database connection SUCCEEDED"
else:
print "Database connection FAILED"

# The following code creates a command object,
# assigns the command to the connection object,
# sets the query, creates the parameters objects to
# be passed to the command object and requests the
# query to be prepared (compiled by the SQL system).

oCmd = Dispatch('ADODB.Command')
oCmd.ActiveConnection = oConn
oCmd.CommandType = adCmdText

oCmd.CommandText = """\
SELECT
VA_MK_YEAR,VA_MK_DESCRIP,VO_VIN_NO,VO_MODEL,VO_BODY,
VO_DESCRIPTION,VO_MODEL_ID
FROM D014800 INNER JOIN D014900
ON VA_MK_NUMBER_VER = VO_MAKE_NO AND
VA_MK_YEAR = VO_YEAR
WHERE VA_MK_YEAR = ? AND VA_MK_DESCRIP = ?
"""

vyear = ''
vmake = ''
oParmYear = oCmd.CreateParameter(vyear,adChar,adParamInput)
oParmYear.Size = 4
oParmMake = oCmd.CreateParameter(vmake,adChar,adParamInput)
oParmMake.Size = 10

oCmd.Parameters.Append(oParmYear)
oCmd.Parameters.Append(oParmMake)

oCmd.Prepared = True

...

def wrkveh(ifile,strstart,maxcnt):
""" wrkveh function does an SQL record lookup to try an select
the correct vehicle in the V1sta make and model files.  If the
correct model is found I move V1sta's make model and body
descriptions to the flat file.  Currently, I hard code a 1 for
vehicle use.  The drive segment is an occurs 6"""
cnt = 0
vehwrk = ''
while cnt < maxcnt:
if ifile[strstart:strstart + 10] == '  ':
vehwrk = vehwrk + ifile[strstart:strstart + 133]
else:
vmake = ifile[strstart:strstart + 10]
vyear = ifile[strstart + 98:strstart + 102]
vvin4_8 = ifile[strstart +53:strstart + 58]
vmodel = ''
vbody = ''
oParmYear.Value = vyear
oParmMake.Value = vmake
(oRS, result) = oCmd.Execute()
while not oRS.EOF:
wvin =
oRS.Fields.Item("VO_VIN_NO").Value.replace('*','.')
wvin.replace('*','.')
wvin = wvin[0:5]
r1 = re.compile(wvin)
if r1.match(vvin4_8):
vmake = oRS.Fields.Item("VA_MK_DESCRIP").Value
vmodel = oRS.Fields.Item("VO_MODEL").Value
vbody = oRS.Fields.Item("VO_DESCRIPTION").Value
vmodelid = oRS.Fields.Item("VO_MODEL_ID").Value
print 'DRC model ' + vmake + ' ' + vyear + ' ' +
vmodel + \
  ' ' + vmodelid
break
else:
oRS.MoveNext()
else:
print 'DRC model NOT FOUND'
vehwrk = vehwrk + vmake + vmodel + vbody
vehwrk = vehwrk + ifile[strstart + 50:strstart + 107]
vehwrk = vehwrk + '1'
vehwrk = vehwrk + ifile[strstart + 108:strstart + 133]
strstart += 133
cnt += 1

return vehwrk

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Compile as static

2005-10-06 Thread Micah Elliott
On Oct 06, [EMAIL PROTECTED] wrote:
> Has anyone had any luck with this? Im trying to compile python 2.4.2 on
> Slackware 10.1 into one large executable. One which contains everything
> required to run python (as static). So python doesn't look for
> dynamically shared objects like libpthread.so.0.
> 
> I have tried ./configure --disable-dynamic
>  --enable-dynamic=NO
>  --enable-static
> 
> However the executable size is always the same :/ Please assist.

ldd is your friend for seeing the dependencies.  I see what you mean,
though.  I'm no autoconf expert, but AFAICT this was not an intended
feature.  My attempted grok of the Makefile also supports this theory.
And I don't see any of the options you specified as being valid.  Using
"--disable-shared" also doesn't affect "python", but does appear to make
libpython static, but I think it is regardless.  You can force the issue
with:

   $ ../configure ...
   $ make LDFLAGS=-static
   $ ls -l ./python
   -rwxr-xr-x  1 mdelliot support 218 Oct  6 08:06 ./python
   $ ldd ./python
   not a dynamic executable

But this gives some import warnings, and running has some problems...

Then I found these, indicating that it is easy ;-)

http://groups.google.com/group/comp.lang.python/browse_frm/thread/9407982ad24b62ec/5018f9abebaa285a?lnk=st&q=build+python+static&rnum=3&hl=en#5018f9abebaa285a

http://groups.google.com/group/comp.lang.python/browse_frm/thread/1ac371489ed4040b/076580464204cd79?lnk=st&q=build+python+static&rnum=5&hl=en#076580464204cd79

http://groups.google.com/group/comp.lang.python/browse_frm/thread/c532cc6469e29488/c6fcc1afbd7c41b0?lnk=st&q=build+python+static&rnum=17&hl=en#c6fcc1afbd7c41b0

It might be nice to have an autoconf option to make this more obvious
for guys like us.  Maybe this is just a rare need.

-- 
Micah Elliott
<[EMAIL PROTECTED]>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: shelve object back to dictionary

2005-10-06 Thread Fredrik Lundh
Ryan Krauss wrote:

> Is there an easy way to convert a shelved object back to a dictionary?
>  When I save a dictionary using shelve and then load it in a later
> session, I have an object whose property names are the keys of the
> dictionary used as an input to shelve.  For example, instead of
> user['name'] I have user.name.  I would prefer to have the scripts I
> write to analyze the saved data have a similar syntax to the ones I
> used to create it, so I would rather deal with a dictionary after I
> load the shelved data.

session 1:

>>> import shelve
>>> db = shelve.open("foo")
>>> d = {"a": 1, "b": 2}
>>> db["key"] = d
>>> print d
{'a': 1, 'b': 2}
>>> print db["key"]
{'a': 1, 'b': 2}
>>> db.close()

session 2:

>>> import shelve
>>> db = shelve.open("foo")
>>> db["key"]
{'a': 1, 'b': 2}
>>> type(db["key"])

>>> db["key"].key
Traceback (most recent call last):
  File "", line 1, in ?
AttributeError: 'dict' object has no attribute 'key'
>>>

are you sure you're saving dictionaries?  what does "print type(obj)" print
for objects from your shelve?  what does the following print for your data-
base ?

>>> import anydbm
>>> db = anydbm.open("")
>>> db[db.keys()[0]]





-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Absolultely confused...

2005-10-06 Thread Tim Peters
[Jeremy Moles]
> ...
> I may be missing something critical here, but I don't exactly grok what
> you're saying; how is it even possible to have two instances of
> PyType_vector3d? It is (like all the examples show and all the extension
> modules I've done in the past) a static structure declared and assigned
> to all at once, only once.

The most common cause is inconsistent import statements, with one
place using package-relative import but another place explicitly
specifying the package.  Here's a simple pure Python example, with
this directory structure:

playground/
package_dir/
__init__.py
source.py
module.py

__init__.py is empty; it just serves to make `package_dir` a package.

source.py defines a single type, named Type:

class Type(object):
pass

module.py imports source.Type in two different ways, then prints various stuff:

from source import Type as one_way # package-relative import
from package_dir.source import Type as another_way

print one_way is another_way
print one_way.__name__, another_way.__name__
print repr(one_way), repr(another_way)

import sys
for k, v in sys.modules.items():
 if "source" in k:
 print k, v

Now _from_ playground, run module.py:

python playground/module.py

This is the output, with annotations; I ran this on Windows, so expect
to see backslashes :

False

That is, one_way is not the same object as another_way:  there are two
distinct instances of the Type object.

Type Type

Although they're distinct, they have the same __name__, "Type".

 

Their reprs differ, though, showing the path via which they were imported.

source 
package_dir.source 

That's two lines of output from crawling over sys.modules:  there are
two distinct instances of the entire `source` module.  That's the real
cause of the multiple `Type` instances.

package-relative import is rarely a good idea.  Are you doing that anywhere?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Swig and pointers

2005-10-06 Thread Java and Swing
(reposting, i was just told how I should properly reply via
groups.google.com)

im sorry, why would it be md_ptr?  what is md_ptr?

i tried..
%include cpointer.i
%pointer_functions(MY_DIGIT, digit_ptr)

ptr = new_digit_ptr()
doIt("a message", ptr)
...doesnt work..still needs a DIGIT **


Miki Tebeka wrote:
> Hello Java,
>
> > ...
> > extern int doIt(char *a, MY_DIGIT **digit);
> > %include cpointer.i
> > %pointer_functions(MY_DIGIT, md_prt);
> Don't you mean md_ptr?
>
> > %typemap(in) (char *a, MY_DIGIT **argv) {
> >   /* Check if is a list */
> >   if (PyList_Check($input)) {
> > int i;
> > $1 = PyList_Size($input);
> > $2 = (MY_DIGIT **) malloc(($1+1)*sizeof(long *));
> > for (i = 0; i < $1; i++) {
> >   PyObject *o = PyList_GetItem($input,i);
> >   if (PyString_Check(o))
> > $2[i] = PyString_AsString(PyList_GetItem($input,i));
> >   else {
> > PyErr_SetString(PyExc_TypeError,"list must contain strings");
> > free($2);
> > return NULL;
> >   }
> > }
> > $2[i] = 0;
> >   } else {
> > PyErr_SetString(PyExc_TypeError,"not a list");
> > return NULL;
> >   }
> > }
> >
> > %typemap(freearg) (char *a, MY_DIGIT **argv) {
> >   free((MY_DIGIT *) $2);
> > }
> >
> >
> > ..from Python I am trying
> >
> > >> ptr = []
> > >> doIt("blah", ptr)
> >
> > I thought this was the correct approach as described here:
> > http://www.swig.org/Doc1.3/SWIGDocumentation.html#Python_nn59
> >
> > However, python comes back and says "TypeError: argument number 2: a
> > 'MY_DIGIT **' is expected, 'list([])' is received"
> >
> > ..any ideas?
> Didn't check it but from http://www.swig.org/Doc1.3/Library.html it looks
> like you need to do:
> ptr = new_md_prt()
>
> HTH.
> --
> 
> Miki Tebeka <[EMAIL PROTECTED]>
> http://tebeka.bizhat.com
> The only difference between children and adults is the price of the toys

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: replacments for stdio?

2005-10-06 Thread Martin Miller
In what way would you like to get "stdin to work"? In Bryan's post in
the Application(Frame).__init__() he binds some lambda functions to key
strokes which allow control-C copying of text in the window.

Seems like additonal application-specific things might be possible, but
then the code would no longer be generic. Interaction with the main
application would likely be tricky because each output window is
lanuched as a separate process when output is first sent to it.

As far a redistribution goes, I would think anything posted to the
public comp.lang.python usenet newgroup is unencumbered unless the
author indicates otherwise -- or at most covered by the same open
source license as Python.

-Martin


[EMAIL PROTECTED] wrote:
> yes,
> I've tried it aswell - nice work indeed!
> 
> now, maybe also get stdin to work from this TK window... ;-)

-- 
http://mail.python.org/mailman/listinfo/python-list


RE: So far

2005-10-06 Thread Bell, Kevin
I like pythonWin other than the white background where you write your scripts, 
because after awhile it's bad on the eyes.  Does anyone know of a free IDE that 
will allow control of this, as well as the coloring of keywords, etc?



-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Christophe
Sent: Thursday, October 06, 2005 9:50 AM
To: [email protected]
Subject: Re: So far

CppNewB a écrit :
> I am absolutely loving my experience with Python.  Even vs. Ruby, the syntax 
> feels very clean with an emphasis on simplification.
> 
> My only complaint is that there doesn't appear to be a great commercial IDE 
> for the language.  I've tried Komodo, etc and they are nice applications, 
> but they don't feel like they give me the "power" like a Visual Studio or 
> Delphi (I wish I could articulate better the differences).Finding a 
> descent GUI builder has been a challenge as well.  Most of them have support 
> for Dialogs, but what about more complex UI's?  I may need a resizable frame 
> within a resizable frame? I haven''t found a GUI builder with a great feel 
> yet.
> 
> Other than that, my experience has been wonderful.  Even after my 
> complaints, I plan on sticking with Python for a while. 

Try PyQT with eric3 as an IDE.

http://www.die-offenbachs.de/detlev/eric3.html
-- 
http://mail.python.org/mailman/listinfo/python-list
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: So far

2005-10-06 Thread Michael Schneider
Take a look at:

http://wingware.com/

It is only $35.00 for an IDE. (30 day free eval version)

I use eclipse for java, and have become quite fond of tab completion.

Mike

CppNewB wrote:
> I am absolutely loving my experience with Python.  Even vs. Ruby, the syntax 
> feels very clean with an emphasis on simplification.
> 
> My only complaint is that there doesn't appear to be a great commercial IDE 
> for the language.  I've tried Komodo, etc and they are nice applications, 
> but they don't feel like they give me the "power" like a Visual Studio or 
> Delphi (I wish I could articulate better the differences).Finding a 
> descent GUI builder has been a challenge as well.  Most of them have support 
> for Dialogs, but what about more complex UI's?  I may need a resizable frame 
> within a resizable frame? I haven''t found a GUI builder with a great feel 
> yet.
> 
> Other than that, my experience has been wonderful.  Even after my 
> complaints, I plan on sticking with Python for a while. 
> 
> 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Simple prototype text editor in python

2005-10-06 Thread thakadu
Thanks Robert

I have packaged it up with distutils and included the
license in the README.txt file.
I think I am missing something as I have only
seen a place (under submissions) on
http://python.org/pypi?%3Aaction=submit_form
to submit the PKG_INFO file, or to submit a url manually
but nowhere to actually upload the distribution file. (the tar.gz file)

Am I looking in the wrong place? Or is it acceptable to post a .tar.gz
file in place of the PKG_INFO file?

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Absolultely confused...

2005-10-06 Thread Jeremy Moles
WELL, I figured it out--thanks to everyone's help. There were instances
of the object and I am a total moron.

Thanks again to everyone who helped me stomp this out. :)

On Wed, 2005-10-05 at 21:58 -0400, Jeremy Moles wrote:
> So, here is my relevant code:
> 
>   PyArg_ParseTuple(args, "O!", &PyType_vector3d, &arg1)
> 
> And here ismy error message:
> 
>   argument 1 must be pylf.core.vector3d, not pylf.core.vector3d
> 
> I know PyType_vector3d "works" (as I can use them in the interpreter all
> day long), and I know I'm passing a pylf.core.vector3d (well, apparently
> not...)
> 
> I've spent hours and hours on this and I'm finally just giving up and
> asking. I've tried everything to get my program to verify that arg1 is
> really a PyType_vector3d, but to no avail.
> 
> If I take out the "!" in the format string and just use "O", I can at
> least get past PyArg_ParseTuple. Then I try something like...
> 
>   PyObject_TypeCheck(arg1, &PyType_vector3d)
> 
> Which also fails, but I know for a fact that arg1's PyObject_Repr is
> what it should be. (pylf.core.vector3d)
> 
> I guess my question is: what in the world could be causing this to fail?
> It seems like I'm just not able to use ParseType or BuildValue to create
> objects of my own type.
> 
> I know I haven't provided a lot of information, but does anyone have any
> ideas or where I should start looking?
> 

-- 
http://mail.python.org/mailman/listinfo/python-list


  1   2   >