[Tutor] MySQLdb install issue

2008-01-15 Thread John
Hello,

Does anyone know how to install MySQLdb into a python installation when the
machine you are working on does not have MySQL installed? I.E. the MySQL
installation is on a different server, but the site.cfg file for the MySQLdb
installation asks for the location of the mysql_config:



# The path to mysql_config.
# Only use this if mysql_config is not on your PATH, or you have some weird
# setup that requires it.
#mysql_config = /usr/local/bin/mysql_config



Thanks!

-- 
Configuration
``
Plone 2.5.3-final,
CMF-1.6.4,
Zope (Zope 2.9.7-final, python 2.4.4, linux2),
Five 1.4.1,
Python 2.4.4 (#1, Jul 3 2007, 22:58:17) [GCC 4.1.1 20070105 (Red Hat
4.1.1-51)],
PIL 1.1.6
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Read protection of python files for Abaqus

2008-01-15 Thread Ferruh KAYHAN
Dear Sir;
Thank you very much for the information.  After I read your e-mail, I
have started to think that our codes are not highly but moderately
valuable.  Therefore, I am satisfied, by using .pyc files.  I am not
very affraid of determined hackers from outside because they will not
understand the usage of my application and a hardcopy of the codes will
always be in my handbag.

Best Regards
Ferruh Kayhan 

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On
Behalf Of Michael Langford
Sent: Monday, January 14, 2008 5:33 PM
To: Ferruh KAYHAN
Cc: tutor@python.org
Subject: Re: [Tutor] Read protection of python files for Abaqus

I know there are a lot of people who are very much for code openness in
all cases. I'm from a couple worlds that's not even something you'd
think about doing (military software, where people die if the other side
gets your code, and embedded software, where a company in china copies
your design and puts you out of business), so you have to work within
this sometimes. That said, many companies *vastly* overvalue their code
base, especially the great balance of it, when really 4-10 modules are
the only valuable parts.

There are obfuscators that generally work for python and then only
shipping .pyc files (as someone suggested above) helps as well.

If the code really is that valuable, I doubt you're going to be able to
hide it well enough a determined, an attacker with a skill level equal
to many of the people on this list, couldn't extract your algorithms.
I'm am not saying .NET is any more secure in that than python is either.
Just introspective languages (Java too), have this issue where they're
quite a bit easier to reverse engineer.

Assuming its only moderately valuable, then the steps above should be
enough.

You may think about isolating the highly valuable algorithm in a C
module then highly optimizing it and running a stripper on it. Then
connect it up to your python code with SWIG. That will defeat the
introspection attacks (they'll only be able to see the interface of the
C module), and the high levels of optimization in the C code (which you
should strip) will hide the algorithm further.

Another possibility is refactoring your algorithm into a code generating
utility which you don't let leave your facility. The generated code will
work, but is not reverse engineerable, as its just something like a
massive lookup table, or a series of decomposed functions.

I've been the guy attacking code before. It all boils down to the
safe/lock issue: Locks and safes aren't there to keep people out
forever, every good lock and safe has an amount of time they expect to
keep people out. You have to have a security guard or something else at
that point to safeguard your valuables. Pick locks that are good enough,
and try to remove the incentives and abilities to break in other ways.

--Michael

PS: I would like to point out. These other people will be able to
*call* your highly proprietary code no matter what you do. So if nothing
else, a determined attacker can just call your code again without
understanding it.
--
Michael Langford
Phone: 404-386-0495
Consulting: http://www.RowdyLabs.com


On 1/14/08, Ferruh KAYHAN [EMAIL PROTECTED] wrote:
 Dear Sir;
 Thank you for your reply.  Oftenly, especially in industrial
companies,
 codes are becoming very valuable and owner of the company likes to
keep
 that value as confidential in order to protect the company
 competitivness.  Somr times, professionals are leaving companies and
 starting new jobs in competitor companies.  Therefore, protecting some
 codes are becoming important.

 So in our case, we are not trying to stop anybody learning python
 language but we are trying to protect what we are doing with python.

 I hope my reply is sufficient.

 Regards

 -Original Message-
 From: bhaaluu [mailto:[EMAIL PROTECTED]
 Sent: Monday, January 14, 2008 3:25 PM
 To: Ferruh KAYHAN
 Cc: tutor@python.org
 Subject: Re: [Tutor] Read protection of python files for Abaqus

 Greetings,
 On Jan 14, 2008 3:17 AM, Ferruh KAYHAN [EMAIL PROTECTED] wrote:
  Dear Sirs;
  Good morning.
  I do not like abaqus users will read my python file codes.  How can
I
  protect my codes from reading ans still workable by Abaqus import??
 
  Best Regards
  Ferruh Kayhan

 quote source=wikipedia?ABAQUS
 Abaqus is widely used in the automotive, aerospace, and industrial
 products industries. The package is very popular with academic and
 research institutions ...
 These software products, especially Abaqus/CAE, extensively use the
 open-source scripting language Python for scripting and customization.
 /quote

 Don't academics and researchers thrive on sharing information?
 Also, this forum is geared towards learning Python, and sharing source
 code is encouraged in order to obtain help.

 Also, many eyes can find and fix bugs in your scripts, as well as,
 others may find the scripts useful: ie. research can advance more
 quickly.


Re: [Tutor] MySQLdb install issue

2008-01-15 Thread Eric Brunson

There is at least on client library that the mysql package needs to link 
against.  You either need to install the libraries on the client machine 
or else build the package statically linked on the server machine and 
move it over prebuilt.

John wrote:
 Hello,
  
 Does anyone know how to install MySQLdb into a python installation 
 when the machine you are working on does not have MySQL installed? 
 I.E. the MySQL installation is on a different server, but the site.cfg 
 file for the MySQLdb installation asks for the location of the 
 mysql_config:
  
  
 
 # The path to mysql_config.
 # Only use this if mysql_config is not on your PATH, or you have some 
 weird
 # setup that requires it.
 #mysql_config = /usr/local/bin/mysql_config
  
 
  
 Thanks!

 -- 
 Configuration
 ``
 Plone 2.5.3-final,
 CMF-1.6.4,
 Zope (Zope 2.9.7-final, python 2.4.4, linux2),
 Five 1.4.1,
 Python 2.4.4 (#1, Jul 3 2007, 22:58:17) [GCC 4.1.1 20070105 (Red Hat 
 4.1.1-51)],
 PIL 1.1.6
 

 ___
 Tutor maillist  -  Tutor@python.org
 http://mail.python.org/mailman/listinfo/tutor
   

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] A faster x in S

2008-01-15 Thread Dinesh B Vadhia
For some significant data pre-processing we have to perform the following 
simple process:

Is the integer x in a list of 13K sorted integers.  That's it except this has 
to be done 100m times with different x's (multiple times).  Yep, a real pain!  

I've put the 13K integers in a list S and am using the is 'x in S' function.

I was wondering if there is anything faster?

Dinesh
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] tree/node class/module

2008-01-15 Thread cedric briner
hello,

I'm wanting to do a GUI for to help people using rsync, du, tar . it 
will provide the --exclude and --include of them.

And I thought that the best way to store data relative to the hierarchy 
filesystem was to store them in a tree structure. But after browsing 
ages on the web, I didn't found any class/modules which implements 
trees, with some comments, and small examples.

Am I just blind ???

I'm looking for a tree of object which will give me stuff like:
  - sibling
  - parent
  - children
  - find
  - insert

Do you have any pointers ??

Ced.

-- 

Cedric BRINER
Geneva - Switzerland
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] A faster x in S

2008-01-15 Thread Kent Johnson
Dinesh B Vadhia wrote:
 For some significant data pre-processing we have to perform the 
 following simple process:
  
 Is the integer x in a list of 13K sorted integers.  That's it except 
 this has to be done 100m times with different x's (multiple times).  
 Yep, a real pain! 
  
 I've put the 13K integers in a list S and am using the is 'x in S' function.
  
 I was wondering if there is anything faster?

Yes. Put the integers in a set and test for membership there. If for 
some reason the integers have to be in a list, and the list is sorted, 
use the bisect module to do a binary search, rather than the linear 
search used by 'x in S'.
http://docs.python.org/lib/module-bisect.html

Kent
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Reading Input Data

2008-01-15 Thread Michael Langford
Accidentally cut off a 0 there...
Think about using ConfigParser instead of your csv. Doug Hellman wrote
a good article on that:
http://blog.doughellmann.com/2007/04/pymotw-configparser.html

But if you really want to load your data this way, this will work:

for subscript,line in enumerate(file(file.csv)):
 s = line.split(,)[1]
 try:
 f = float(s)
 locals()[x%i % subscript]=f
 except:
 locals()[x%i % subscript]=s

print x1
print x0

On Jan 15, 2008 3:47 PM, Michael Langford [EMAIL PROTECTED] wrote:
 for subscript,line in enumerate(file(file.csv)):
  s = line.split(,)[1]
  try:
  f = float(s)
  locals()[x%i % subscript]=f
  except:
  locals()[x%i % subscript]=s

 print x1
 print x

 On Jan 15, 2008 3:26 PM, lechtlr [EMAIL PROTECTED] wrote:

  I want to read an input file (file.csv) that has two columns. I want to read
  2nd column and assign variables that are strings and floats. Currently, I
  use the following split() function to read from the input file and create a
  list, and then assign each element to a variable.
 
  I am wondering there is any other easier (and elegant) way of doing this ?
 
  data = []
  for line in open(file.csv):
   columns = line.split(',')
   data.append([columns[1]])
 
  This script returns, say:
  data = [ ['20.0'], ['0.34'], ,[ 'a:0.20, b:0.30, c:0.50' ]]
 
  Then, I assign to a set of variables, say:
 
  x1 = float(data[0][0]) ; x2 = float(data[1][0]);.;xn =
  data[-1][0]
 
 
  Thanks,
  Lex
 
 
 
 
 
 
 
 
   
  Never miss a thing. Make Yahoo your homepage.

  ___
  Tutor maillist  -  Tutor@python.org
  http://mail.python.org/mailman/listinfo/tutor
 
 



 --
 Michael Langford
 Phone: 404-386-0495
 Consulting: http://www.RowdyLabs.com




-- 
Michael Langford
Phone: 404-386-0495
Consulting: http://www.RowdyLabs.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Reading Input Data

2008-01-15 Thread Kent Johnson
Michael Langford wrote:
 for subscript,line in enumerate(file(file.csv)):
  s = line.split(,)[1]
  try:
f = float(s)
locals()[x%i % subscript]=f
  except:
locals()[x%i % subscript]=s

Don't do this!

For one thing, writing to locals() doesn't always work. Specifically, 
writing to locals() inside a function does *not* affect the local namespace:
In [28]: def foo():
: locals()['x'] = 1
: print x
:
:
In [29]: foo()

Traceback (most recent call last):
   File ipython console, line 1, in module
   File ipython console, line 3, in foo
type 'exceptions.NameError': global name 'x' is not defined


Writing to globals() might be marginally better but not much. (When not 
in a function, locals() is actually the same as globals() and the above 
code will work.)

In most cases where someone is trying to assign a bunch of names like 
this, a better solution is to use a dictionary (or possibly a list) to 
hold the data.

Kent
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Input

2008-01-15 Thread Ricardo Aráoz
Last week someone had an issue with raw_input() and how to get input for
a number. So I remembered my CP/M times and got to think of a little
function I had there. The function is lost and my time is scarce but I
made a little effort and here you have the results. It has loads of room
for improvement and probably a few bugs but it's a starting point, and
it should guarantee that you get the input you need.
You just define your mask and the functions checks the input
accordingly, it returns a string.
You might improve it by displaying the mask, e.g. for mask = '.99'
you might see in the screen .__ or for mask = '999-AAA::' you'd
see ___-___::___ so the user will know the format of what's expected of
him, also a beep on incorrect entry might prove nice.

HTH

---
import msvcrt

_validChars = {
'X' :
'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890'
, '9' : '1234567890'
, '-' : '-1234567890'
, 'A' :
'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
, '!' : 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'}
_validKeys = _validChars.keys()

def maskInput(mask, separators = True) :
lmask = list(mask)
lmask.reverse()
usedMask = []
retInput = ''
c = ''
maskChar = lmask.pop()
try :
while maskChar not in _validKeys :
if separators :
retInput += maskChar
msvcrt.putch(maskChar)
maskChar = lmask.pop()
except IndexError : pass

c = msvcrt.getch()
while c != chr(13) :
if maskChar and maskChar not in _validKeys and c in
_validChars[lmask[-1]] :
if separators :
retInput += maskChar
msvcrt.putch(maskChar)
usedMask.append(maskChar)
maskChar = lmask.pop()
if usedMask and c == '\b' :
try :
if maskChar :
lmask.append(maskChar)
maskChar = usedMask.pop()
retInput = retInput[:-1]
msvcrt.putch(c)
msvcrt.putch(' ')
msvcrt.putch(c)
while usedMask[-1] not in _validKeys :
if maskChar :
lmask.append(maskChar)
maskChar = usedMask.pop()
if separators :
retInput = retInput[:-1]
msvcrt.putch(c)
msvcrt.putch(' ')
msvcrt.putch(c)
except IndexError : pass
elif maskChar and c in _validChars[maskChar] :
retInput += c
msvcrt.putch(c)
try :
usedMask.append(maskChar)
maskChar = lmask.pop()
  #  while maskChar not in _validKeys :
except IndexError :
maskChar = ''
c = msvcrt.getch()
return retInput

if __name__ == '__main__' :
invar = maskInput('-.99')
print
print invar


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Reading Input Data

2008-01-15 Thread bob gailer
lechtlr wrote:
 I want to read an input file (file.csv) that has two columns. I want 
 to read 2nd column and assign variables that are strings and floats. 
 Currently, I use the following split() function to read from the input 
 file and create a list, and then assign each element to a variable.
In addition to Jay (it's csv module not cvs) and Michael's responses I add:

It is rarely a good idea to assign a bunch of variables (x1...xn).

What's the reason you're doing this?

You can just create another list holding the floated values. If you 
assign this list to x then you can refer to x[0], x[1], ...x[n].

Also you have created lists within your list, to no apparent purpose;

Consider:

x = [float(line.split(',')[1]) for line in open(file.csv)]

Bob
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] tree/node class/module

2008-01-15 Thread bob gailer
cedric briner wrote:
 hello,

 I'm wanting to do a GUI for to help people using rsync, du, tar . it 
 will provide the --exclude and --include of them.

 And I thought that the best way to store data relative to the hierarchy 
 filesystem was to store them in a tree structure. But after browsing 
 ages on the web, I didn't found any class/modules which implements 
 trees, with some comments, and small examples.
   
Some googling led to:

http://www.velocityreviews.com/forums/t355467-tree-and-graph-structures-in-python.html

I have not looked up the links therein but the titles sound promising.

We could roll our own if all else fails.

[snip]

Bob
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] A faster x in S

2008-01-15 Thread bob gailer
Dinesh B Vadhia wrote:
 For some significant data pre-processing we have to perform the 
 following simple process:
  
 Is the integer x in a list of 13K sorted integers.  That's it except 
 this has to be done 100m times with different x's (multiple times).  
 Yep, a real pain! 
  
 I've put the 13K integers in a list S and am using the is 'x in S' 
 function.
  
 I was wondering if there is anything faster?
I agree with Kent.

  l = range(13000)
  s=set(l)
  d=dict(enumerate(l))
  import time
  def f(lookupVal, times, values):
... st=time.time()
... for i in range(times):
... z = lookupVal in values
... return time.time()-st   
  f(6499,1000,l)
0.3126376037598
  f(6499,100,s)
0.3123623962402

So set is 1000 times faster than list!

  f(6499,100,d)
0.31300020217895508

And dict is (as expected) about the same as set.

So 100,000,000 lookups should take about 30 seconds. Not bad, eh?

Let's explore another angle. What range are the integers in (min and max)?

Bob
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Reading Input Data

2008-01-15 Thread Michael Langford
I'd like to be clear, this isn't a clean thing for the middle of a big
program. I was thinking the entire time I was testing it I wonder why
anyone would need to do this

But if you have a python program you'd probably call a script, used
for one simple task, it can be appropriate (with Kent's catch on the
globals/local thing). I assumed you were using your approach for
something like that. (would you tell us what you're doing this for
btw? The suspense ... :o))

If you're doing something like multivariable analysis or something
else that you would do in software like maple, this approach can
greatly simplify the notation over the list/dict approach.

If you're not using python as a huge substitute for a math solver,
then avoid what I said like the plague and use a dict.

  --Michael

On 1/15/08, Michael Langford [EMAIL PROTECTED] wrote:
 Accidentally cut off a 0 there...
 Think about using ConfigParser instead of your csv. Doug Hellman wrote
 a good article on that:
 http://blog.doughellmann.com/2007/04/pymotw-configparser.html

 But if you really want to load your data this way, this will work:

 for subscript,line in enumerate(file(file.csv)):
  s = line.split(,)[1]
  try:
  f = float(s)
  locals()[x%i % subscript]=f
  except:
  locals()[x%i % subscript]=s

 print x1
 print x0

 On Jan 15, 2008 3:47 PM, Michael Langford [EMAIL PROTECTED] wrote:
  for subscript,line in enumerate(file(file.csv)):
   s = line.split(,)[1]
   try:
   f = float(s)
   locals()[x%i % subscript]=f
   except:
   locals()[x%i % subscript]=s
 
  print x1
  print x
 
  On Jan 15, 2008 3:26 PM, lechtlr [EMAIL PROTECTED] wrote:
 
   I want to read an input file (file.csv) that has two columns. I want to 
   read
   2nd column and assign variables that are strings and floats. Currently, I
   use the following split() function to read from the input file and create 
   a
   list, and then assign each element to a variable.
  
   I am wondering there is any other easier (and elegant) way of doing this ?
  
   data = []
   for line in open(file.csv):
columns = line.split(',')
data.append([columns[1]])
  
   This script returns, say:
   data = [ ['20.0'], ['0.34'], ,[ 'a:0.20, b:0.30, c:0.50' 
   ]]
  
   Then, I assign to a set of variables, say:
  
   x1 = float(data[0][0]) ; x2 = float(data[1][0]);.;xn =
   data[-1][0]
  
  
   Thanks,
   Lex
  
  
  
  
  
  
  
  

   Never miss a thing. Make Yahoo your homepage.
 
   ___
   Tutor maillist  -  Tutor@python.org
   http://mail.python.org/mailman/listinfo/tutor
  
  
 
 
 
  --
  Michael Langford
  Phone: 404-386-0495
  Consulting: http://www.RowdyLabs.com
 



 --
 Michael Langford
 Phone: 404-386-0495
 Consulting: http://www.RowdyLabs.com



-- 
Michael Langford
Phone: 404-386-0495
Consulting: http://www.RowdyLabs.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Input

2008-01-15 Thread Tiger12506
Try regular expressions in the re module. This should make this code below 
much much simpler. Downside is you have to learn a slightly different 
syntax. Upside is - regular expressions are very powerful.



 Last week someone had an issue with raw_input() and how to get input for
 a number. So I remembered my CP/M times and got to think of a little
 function I had there. The function is lost and my time is scarce but I
 made a little effort and here you have the results. It has loads of room
 for improvement and probably a few bugs but it's a starting point, and
 it should guarantee that you get the input you need.
 You just define your mask and the functions checks the input
 accordingly, it returns a string.
 You might improve it by displaying the mask, e.g. for mask = '.99'
 you might see in the screen .__ or for mask = '999-AAA::' you'd
 see ___-___::___ so the user will know the format of what's expected of
 him, also a beep on incorrect entry might prove nice.

 HTH

 ---
 import msvcrt

 _validChars = {
'X' :
 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890'
, '9' : '1234567890'
, '-' : '-1234567890'
, 'A' :
 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
, '!' : 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'}
 _validKeys = _validChars.keys()

 def maskInput(mask, separators = True) :
lmask = list(mask)
lmask.reverse()
usedMask = []
retInput = ''
c = ''
maskChar = lmask.pop()
try :
while maskChar not in _validKeys :
if separators :
retInput += maskChar
msvcrt.putch(maskChar)
maskChar = lmask.pop()
except IndexError : pass

c = msvcrt.getch()
while c != chr(13) :
if maskChar and maskChar not in _validKeys and c in
 _validChars[lmask[-1]] :
if separators :
retInput += maskChar
msvcrt.putch(maskChar)
usedMask.append(maskChar)
maskChar = lmask.pop()
if usedMask and c == '\b' :
try :
if maskChar :
lmask.append(maskChar)
maskChar = usedMask.pop()
retInput = retInput[:-1]
msvcrt.putch(c)
msvcrt.putch(' ')
msvcrt.putch(c)
while usedMask[-1] not in _validKeys :
if maskChar :
lmask.append(maskChar)
maskChar = usedMask.pop()
if separators :
retInput = retInput[:-1]
msvcrt.putch(c)
msvcrt.putch(' ')
msvcrt.putch(c)
except IndexError : pass
elif maskChar and c in _validChars[maskChar] :
retInput += c
msvcrt.putch(c)
try :
usedMask.append(maskChar)
maskChar = lmask.pop()
  #  while maskChar not in _validKeys :
except IndexError :
maskChar = ''
c = msvcrt.getch()
return retInput

 if __name__ == '__main__' :
invar = maskInput('-.99')
print
print invar

 
 ___
 Tutor maillist  -  Tutor@python.org
 http://mail.python.org/mailman/listinfo/tutor
 

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Input

2008-01-15 Thread Ricardo Aráoz
Tiger12506 wrote:
 Try regular expressions in the re module. This should make this code below 
 much much simpler. Downside is you have to learn a slightly different 
 syntax. Upside is - regular expressions are very powerful.
 

Of course I know and use reg. exps., the point of the function is not to
validate input but to force the proper input.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Rs: help, thanks very much.

2008-01-15 Thread bill.wu

i am new guy.
i ask a easy question.

why the first one havex,the second one doesn't have x. what is different? 
when write x,when don't write x.

in my point,the second one don't def variable.

(1)

def func(x):
print 'x is', x
x = 2
print 'Changed local x to', x

x = 50
func(x)
print 'x is still', x (2)

def func():
global x

print 'x is', x
x = 2
print 'Changed local x to', x

x = 50
func()
print 'Value of x is', x 


DreamMail - 第一次不用是你的错,第二次不用是我的错 www.dreammail.org
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Rs: help, thanks very much.

2008-01-15 Thread Eric Brunson

Did you read the entire discussion at
http://www.ibiblio.org/g2swap/byteofpython/read/local-variables.html?

What did you understand and not understand?

Sincerely,
e.

bill.wu wrote:
 i am new guy.
 i ask a easy question.
 why the first one havex,the second one doesn't have x. what is
 different? when write x,when don't write x.
 in my point,the second one don't def variable.
 (1)
 def |func||*(x)*:|
 | print ||'x is'||, x|
 | x = ||2|
 | print ||'Changed local x to'||, x|

 |x = ||50|
 |func*(x)*|
 |print ||'x is still'||, x|
   
 (2)
 def |func||*()*:|
 | global ||x|

 | print ||'x is'||, x|
 | x = ||2|
 | print ||'Changed local x to'||, x|

 |x = ||50|
 |func*()*|
 |print ||'Value of x is'||, x|

 
 /*DreamMail*/ - 第一次不用是你的错,第二次不用是我的错
 www.dreammail.org http://www.dreammail.org
 

 ___
 Tutor maillist  -  Tutor@python.org
 http://mail.python.org/mailman/listinfo/tutor
   

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Input

2008-01-15 Thread Kent Johnson
Ricardo Aráoz wrote:

 _validChars = {
 'X' :
 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890'
 , '9' : '1234567890'
 , '-' : '-1234567890'
 , 'A' :
 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
 , '!' : 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'}
 _validKeys = _validChars.keys()

snip
 while maskChar not in _validKeys :

There is no need to make _validKeys, you can write
   while maskChar not in _validChars
which is actually more efficient, in general, because it is a hash table 
lookup instead of searching a list.

Kent
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Input

2008-01-15 Thread Tiger12506
 Of course I know and use reg. exps., the point of the function is not to
 validate input but to force the proper input.

So? Are you going to try to tell me that you can force particular input 
without actually determining if its valid or not first? ;-)

Just a thought. 

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] A faster x in S

2008-01-15 Thread Danny Yoo
Kent and Bob,

Are you thinking of the first problem in Bentley's Programming Pearls? 
The original poster's questions sounds like it could be in that domain.

 http://netlib.bell-labs.com/cm/cs/pearls/cto.html

So I agree: the next questions we probably should ask the original poster:

* Why are you trying to search for a number in those sorted integers?


* Is there anything characteristic about those sorted integers that
  might be peculiar or useful?  Do the numbers have streaks?  Are the
  integers large or small?
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] help, thanks very much.

2008-01-15 Thread bill.wu

i am new guy.
i ask a easy question.
 
why the first one havex,the second one doesn't have x. what is different? 
when write x,when don't write x.

in my point,the second one don't def variable.

(1)

def func(x):
print 'x is', x
x = 2
print 'Changed local x to', x

x = 50
func(x)
print 'x is still', x (2)

def func():
global x

print 'x is', x
x = 2
print 'Changed local x to', x

x = 50
func()
print 'Value of x is', x 
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] get_python_lib()

2008-01-15 Thread Kakada
Hi list,

I was just wondering why the below function return different location on 
different machine?

import distutils.sysconfig
distutils.sysconfig.get_python_lib()

On my computer:
'/usr/lib/python2.5/site-packages'
On my friend's computer:
'/usr/local/lib/python2.5/site-packages'

What is the difference between these two?
Note: I have both location on my filestem.

Thanks for your input.

dada


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] help, thanks very much.

2008-01-15 Thread Brendan Rankin
bill.wu bill.wws at gmail.com writes:

 
 
  
 i am new guy.
 i ask a easy question.
  
 why the first one havex,the second one doesn't have x. what 
 is different? when write x,when don't write x.
  
 in my point,the second one don't def variable.
  
 

Variable scope.  By declaring the x as global, any changes to x in func() will
affect x outside the function, as well.


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] parsing html.

2008-01-15 Thread Shriphani Palakodety
Hello,
I have a html document here which goes like this:

A name=4/abTable of Contents/b
.
A name=5/abPreface/b

Can someone tell me how I can get the string between the b tag for
an a tag for a given value of the name attribute.

Thanks,
Shriphani Palakodety
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] get_python_lib()

2008-01-15 Thread Vishnu Mohan
Kakada wrote:
 Hi list,

 I was just wondering why the below function return different location on 
 different machine?

 import distutils.sysconfig
 distutils.sysconfig.get_python_lib()
 On my computer:
 '/usr/lib/python2.5/site-packages'
 On my friend's computer:
 '/usr/local/lib/python2.5/site-packages'

 What is the difference between these two? Note: I have both location on my 
 filestem.
   

Most of the packages will install itself, by default, into 
/usr/local/lib/python$VER/site-packages/(third-party).
But most distibutions will put their software into 
/usr/lib/python$VER/site-packages/. May be your friend might
have changed $PYTHONHOME like env's so that it is pointing to /usr/local 
or while installing the python he might have
set --prefix to the /usr/local/

-VishnuMohan, Montalvo Systems.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] tree/node class/module

2008-01-15 Thread cedric briner
usefull page

 http://www.velocityreviews.com/forums/t355467-tree-and-graph-structures-in-python.html
  

thanks again

Ced.

-- 

Cedric BRINER
Geneva - Switzerland
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor