[Tutor] #!/usr/bin/env python vs #!/usr/local/bin/python

2007-06-14 Thread emilia12
hi list,

how to choose between #!/usr/bin/env python and
#!/usr/local/bin/python in the beginning of the script ?
e.



-

SCENA - Ĺäčíńňâĺíîňî ÁĹÇĎËŔŇÍÎ ńďčńŕíčĺ çŕ ěîáčëíč ęîěóíčęŕöčč č ňĺőíîëîăčč.
http://www.bgscena.com/

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


[Tutor] how to seed up?

2007-05-19 Thread emilia12
hi list

when i have many modules in my script (eg. 'import pylab,
os, sys'), python loads them very slow ...

so is there a way to run same script many times (with small
changes in the code), without reloading/parsing all modules
each time ?

and 2nd question - in case of CGI script - is there a way to
recall faster already loaded/called script?

Regards,
e.

-

SCENA - Единственото БЕЗПЛАТНО списание за мобилни комуникации и технологии.
http://www.bgscena.com/

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


Re: [Tutor] Running and passing variables to/from

2007-05-06 Thread emilia12
 hi john,
what about f2py - Fortran to Python interface generator

Port description for lang/f2py

Writing Python C/API wrappers for Fortran routines can be a
very tedious task,
especially if a Fortran routine takes more than 20 arguments
but only few of
them are relevant for the problems that they solve. So, I
have developed a
tool that generates the C/API modules containing wrapper
functions of Fortran
routines. I call this tool as F2PY - Fortran to Python
Interface Generator.
It is completely written in Python language and can be
called from the command
line as f2py.

WWW: http://cens.ioc.ee/projects/f2py2e/

e.

-

SCENA - Единственото БЕЗПЛАТНО списание за мобилни комуникации и технологии.
http://www.bgscena.com/

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


[Tutor] how to split a stream of chars

2007-04-09 Thread emilia12
hi list,

i have a long stream of data, represented in hexadecimal
form. I need to split it in bytes (by 2 chars each). eg
'00010203040506'... - ['00', '01, '02' ...].
So my question is: is there an inverse function of zip, or
an easy way to split this long string in pairs (without
indexing in cycle, nor regexpr.)?

Emily

-

SCENA - Единственото БЕЗПЛАТНО списание за мобилни комуникации и технологии.
http://www.bgscena.com/

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


[Tutor] from X import Y vs import X

2007-03-21 Thread emilia12
Hi list,

In Python books one can read that from X import Y is
better than import X, but some times (IMO) it is not.

for eg. in SciPy,

from numpy import matrix
from scipy.linalg import inv, det, eig
A=matrix([[1,1,1],[4,4,3],[7,8,5]])
print det(A)

crashes with :
RuntimeError: module compiled against version 102 of
C-API but this version of numpy is 109
RuntimeError: module compiled against version 102 of
C-API but this version of numpy is 109

BUT next code works fine:

from numpy import matrix
import numpy
A=matrix([[1,1,1],[4,4,3],[7,8,5]])
print numpy.linalg.det(A)

no crashes at all!

i am using: Python 2.4.4 (#71, Oct 18 2006, 08:34:43) [MSC
v.1310 32 bit (Intel)] on win32
and the last version of SciPy ...

my actual question is is this a rare case related to the
scipy distribution, or something general in python

regards,
e.












-

SCENA - Единственото БЕЗПЛАТНО списание за мобилни комуникации и технологии.
http://www.bgscena.com/

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


[Tutor] arguments

2007-02-15 Thread emilia12


Hi list,

I have a function with two arguments (say f(x,y))
and second which returns tuple (say def g(): return (xx,yy))

my question is how to put returned values from g() as
arguments to f ?

the direct way generates error:

f(g())
TypeError: ff() takes exactly 2 arguments (1 given)

and the hard way is
x, y = g()
f(x,y)

is ok but it uses two extra variables. Is there a simple way
to do this?

BTW f(g()[0], g()[1]) works too, but calls function g()
twice ...

thanks in advance
e.



-

SCENA - Единственото БЕЗПЛАТНО списание за мобилни комуникации и технологии.
http://www.bgscena.com/

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


[Tutor] it is about definitions

2007-01-16 Thread emilia12

is there a difference between:

class foo:

and

class foo():

or between these function definitions:

def bar():

and

def bar:

?

thanks in advance
E.


-

Станете част от Европейското On-line семейство! 
Регистрирайте .EU домейн на изключителна цена от 15,90 лв.! 
www.SuperHosting.bg - Динамични Хостинг Решения 

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


[Tutor] [tutor] sort a list

2006-12-23 Thread emilia12
Hi List,

I have a list like this x=[7,4,2,6]
and print x.sort()
gives to me None ! :

 x=[7,4,2,6]
 print x.sort()
None

... but

 x=[7,4,2,6]
 x.sort()
 print x
[2, 4, 6, 7]

so, why list.sort() returns None? is this normal ?

(the python is Python 2.4.3 (#69, Mar 29 2006, 17:35:34)
[MSC v.1310 32 bit (Intel)] on win32)

E.


-

Започва новото голямо приключение!
Ерагон: от 15 декември в кината.
http://reklama.mail.bg/eragon/

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


[Tutor] [tutor] string encode

2006-09-19 Thread emilia12

hi list

is there a way to solve the error in case of :
code
# ...
return str(val) #where val is unicode (eg val = u'u')
/code

so, how register(?) all imported modules to convert all
unicodes to str() with a coder, for eg. encode('cp1251')

thanks in advance

-e-

-

Део и Фани Коларова във филма Бунтът на L
От 22 септември в кината.
http://www.buntatnal.com/

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


[Tutor] UnicodeEncodeError

2006-09-15 Thread emilia12
Hi list,

i am using site-package (webPy) that generates
UnicodeEncodeError: 'ascii' codec can't encode characters
in position 0-6: ordinal not in range(128).

The full message is:
Traceback (most recent call last):
  File c:\python24\lib\site-packages\web.py, line 1786, in
run_wsgi_app
result = self.server.app(env, self.wsgi_start_response)
  File c:\python24\lib\site-packages\web.py, line 1662, in
wsgifunc
result = func()
  File c:\python24\lib\site-packages\web.py, line 1642, in
lambda
func = lambda: handle(inp, fvars)
  File c:\python24\lib\site-packages\web.py, line 920, in
handle
return tocall(*([urllib.unquote(x) for x in args] +
fna))
  File wb03.py, line 24, in GET
web.render('view.html')
  File c:\python24\lib\site-packages\web.py, line 1543, in
render
return output(str(compiled_tmpl))
  File c:\Python24\Lib\site-packages\Cheetah\Template.py,
line 990, in __str__
def __str__(self): return getattr(self, mainMethName)()
  File string, line 93, in respond
  File c:\python24\lib\site-packages\web.py, line 1496, in
filter
return htmlquote(str(val))
UnicodeEncodeError: 'ascii' codec can't encode characters in
position 0-6: ordinal not in range(128)


So, how can i fix this (from outside of this package)? The
attempt with # -*- coding: utf-8 -*- does not solve this
problem...


cheers
-e-


-

Виж това УНИКАЛНО предложение  :-) 
Хостинг на НЕВЕРОЯТНА ЦЕНА - 1,50 лв./месец!
www.SuperHosting.bg - Динамичните Хостинг Решения 


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


[Tutor] [tutor] how to cast to stucture

2006-09-05 Thread emilia12


Hi list,

i have a complex data in binary file and i want to read its
fields... the C way is to read file in buffer and then cast
it to proper structure. Is there a way to do the same in
Python or i have to read the data byte by byte ?

Regards,
E.

-

Спортни залагания!
bg.sportingbet.com

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


Re: [Tutor] threads and webpy

2006-08-17 Thread emilia12
 I just looked at web.py.
 It's not a webserver.  It's a toolkit you use to write
 your own webserver.
 Why are you under the impression that it's a webserver?
 Did you just google for 'web server in Python' and find
 this?

you are right, i mean that it is the core of the webserver

 If you're using some code that you've written (or found)
 to handle web
 requests
 using the 'web.py' module, then show us your code and
 we'll tell you
 how to make it into a class that listens on a single IP
 and how to
 start two listen() methods of the class using threads, or
 maybe even
 handling multiple IPs using a single class instance.
 But just knowing that you are using 'web.py' isn't very
 helpful.
 What actual code are you using to run the webserver?
i am playng around this code :
code
import socket
import sys
import web
import datetime

urls = (
'/(.*)', 'view'
)

class view:
def GET(self, name):
print datetime.datetime.today()

if __name__ == __main__:
hostname = socket.gethostname()
ip = socket.gethostbyname(hostname)
sys.argv.append(ip +':8080') # -- probably this is not
the right way, but it works
web.run(urls)

/code

 (Or maybe web.py contains a simple webserver in the
 module when it's run
 as main?)
yes - in this case it responds to http request like a server

regards
e.

-

Как да получите 10% отстъпка от цените
за оригинални консумативи и принтери на HP
http://digiteq.com/

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


[Tutor] about threads

2006-08-16 Thread emilia12
Hi all,

my question is probably about the threads... I have two IPs
and i want to run web.py server for each IP in the same
time from one script file. I can run them in two command
boxes (and this works) but i want to do this from one ;-)
Maybe i can do this with 'threads' but how ? is there some
example ??

regards
e.

-

��� ��  10%  �� ��
�� �� ��� �  �� HP
http://digiteq.com/

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


[Tutor] threads and webpy

2006-08-16 Thread emilia12
 Hi!
Hi !

 I don't know what web.py is.
 Is it something you wrote?
no, this is a simple webserver, (http://webpy.org/)
 You'll have to write multi-threaded code if you want it
 to run multiple
 threads :)
 (Unless, of course, Web.py supports threads?)

i will ask the authors about this ...

 What's your experience with Python?
 Do you need help with threads in general? threads in
 Python?
yes, but python related part of threads
  Maybe i can do this with 'threads' but how ? is there
 some
  example ??
 There are plenty of examples of threaded code that you
 could find by
 googling around,
 or do you mean 'is there some example [of multi-threading
 the web.py
 program]??'
 If the latter case, I guess you could find that by
 googling as well, if
 it exists.
yes - i will ask the webpy authors

but i expected to fond out a way to start two (or more)
scripts (web.py) in different threads from one puthon's
scrypt. OR two pythons interpretators to execute the above
scrypt ?

cheers
e.


-

Колите. Само в кината от 4 август.

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


[Tutor] [tutor] how to get the fileextention?

2006-07-20 Thread emilia12
Hi,

is this the right (shortest) way to get the file extention
(under MS WIN)?


def getext(fname):
ext = fname.split('.').pop()
return ext

Regards,
Emily

-

B2B портал за продуктите на HP
Цени, спецификации, on-line поръчки, доставка.
Регистрирайте се на http://hp.most.bg

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


Re: [Tutor] [tutor] how to get the fileextention?

2006-07-20 Thread emilia12
Hi Ziyad
thank you very much!

E.

Цитат на писмо от  ?? ? ???
[EMAIL PROTECTED]:

 On Thu, 2006-07-20 at 11:19 +0300, [EMAIL PROTECTED]
 wrote:
  Hi,
 
  is this the right (shortest) way to get the file
 extention
  (under MS WIN)?
 
 
  def getext(fname):
  ext = fname.split('.').pop()
  return ext
 
  Regards,
  Emily
 
 The following maybe a little better:
 def getExt(fname):
   return fname.rsplit('.', 1)[1]

 It uses one method instead of two compared to yours.  And
 in your code
 there's no need for the ‘ext’ variable, you could use:
 def getext(fname):
   return fname.split('.').pop()

 For more information about ‘str’ objects type the
 following inside the
 Python shell:
help(str)


 Ziyad.







-

Спортни залагания!
bg.sportingbet.com

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


[Tutor] [tutor] debug process

2006-06-13 Thread emilia12
Hello,

Is there a way to debug (trace) the python code line by
line?

emily



-

Поличба 666.
Само в кината.


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


[Tutor] [tutor] dictionary

2006-06-07 Thread emilia12


Hi,

how can i print a dictionary, sorted by the values?



-

Поличба 666.
Само в кината.


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