about functions question
I try it: def b(): ... a() ... def a(): ... b() ... b() it's not work. Is it possible pre-define function like in c++ or place functions code after main block? int a(); int b(); int main () { ... a(); ... } int a() { ... b(); ... } int b() { ... a(); ... } =) sorry for my eng;) -- http://mail.python.org/mailman/listinfo/python-list
Re: about functions question
sorry! Yes it's work. What about 2 question? Can i put function after main block? print qq() def qq(): return 'hello' Traceback (most recent call last): File "C:\Python25\projects\indexer\test.py", line 1, in print qq() NameError: name 'qq' is not defined Or onli possible: def main(): print qq() def qq(): return 'hello' main() -- http://mail.python.org/mailman/listinfo/python-list
How can i do this in Python?
perl -ane "print join(qq(\t),@F[0,1,20,21,2,10,12,14,11,4,5,6]).qq(\n)" file.txt -a autosplit mode with -n or -p (splits $_ into @F) -n assume "while (<>) { ... }" loop around program -- http://mail.python.org/mailman/listinfo/python-list
Re: How can i do this in Python?
Thanks;) On 25 Янв., 17:47, Gabriel Genellina <[EMAIL PROTECTED]> wrote: > At Thursday 25/1/2007 01:25, NoName wrote: > > >perl -ane "print join(qq(\t),@F[0,1,20,21,2,10,12,14,11,4,5,6]).qq(\n)"Must > >be done on a single line? > I'm not sure if I've got right the behavior - it's been some time > since I quit writing Perl code. The script iterates over all lines > contained on all files specified on the command line; for each line, > splits it on whitespace; then it prints a selected set of fields > (columns 0, 1, 20, 21...) using a tab character as field separator. > > === cut === > import operator,fileinput > > mapper = map(operator.itemgetter, [0,1,20,21,2,10,12,14,11,4,5,6]) > for line in fileinput.input(): > fields = line.split() > print '\t'.join(m(fields) for m in mapper) > === cut === > > -- > Gabriel Genellina > Softlab SRL > > __ > Preguntá. Respondé. Descubrí. > Todo lo que querías saber, y lo que ni imaginabas, > está en Yahoo! Respuestas (Beta). > ¡Probalo ya!http://www.yahoo.com.ar/respuestas -- http://mail.python.org/mailman/listinfo/python-list
Random passwords generation (Python vs Perl) =)
Perl: @char=("A".."Z","a".."z",0..9); do{print join("",@char[map{rand @char}(1..8)])}while(<>); !!generate passwords untill U press ctrl-z Python (from CookBook): from random import choice import string print ''.join([choice(string.letters+string.digits) for i in range(1,8)]) !!generate password once :( who can write this smaller or without 'import'? -- http://mail.python.org/mailman/listinfo/python-list
Re: Random passwords generation (Python vs Perl) =)
Hmmm.. In the Perl example password generates after user hit ENTER not continously like in Python you wrote... :) i want see various ways to generate passwords even if they some indirect like using BASE64 thanks all p.s. sorry for my eng ;) -- http://mail.python.org/mailman/listinfo/python-list
Re: Random passwords generation (Python vs Perl) =)
WOW! :shock: in this case: while 1:i=__import__;print i('binascii').b2a_base64(i('os').urandom(6)),;raw_input() On 30 Янв., 04:06, "Szabolcs Nagy" <[EMAIL PROTECTED]> wrote: > > while > > 1:i=__import__;print''.join(i('random').choice(i('string').letters > > +'1234567890')for x in range(8)),;raw_input()while > 1:i=__import__;r='random';print''.join(i(r).choice(i('string').letters > +'1234567890')for x in`r`),;raw_input() > > even shorter: > range -> `'random'` > > :) -- http://mail.python.org/mailman/listinfo/python-list
Why?
# -*- coding: cp1251 -*- from glob import glob src= "C:\\\\Новая папка\\*.*" print glob(src) ['C:\\\\\xcd\xee\xe2\xe0\xff \xef\xe0\xef\xea\xe0\\ksdjfk.txt', 'C: \\\\\xcd\xee\xe2\xe0\xff \xef \xe0\xef\xea\xe0\\\xeb\xfb\xe2\xee\xe0\xeb\xee\xe0\xeb.txt'] Why not "C:\\\\Новая папка\\ksdjfk.txt" and etc? -- http://mail.python.org/mailman/listinfo/python-list
Re: Why?
thanx a lot!! On 6 Фев., 12:04, "Gabriel Genellina" <[EMAIL PROTECTED]> wrote: > En Mon, 05 Feb 2007 21:32:23 -0300, NoName <[EMAIL PROTECTED]> escribio: > > > # -*- coding: cp1251 -*- > > from glob import glob > > > src= "C:\\\\Новая папка\\*.*" > > print "src=",src > print "repr(src)=",repr(src)> print glob(src) > > for fn in glob(src): >print fn > > > > > ['C:\\\\\xcd\xee\xe2\xe0\xff \xef\xe0\xef\xea\xe0\\ksdjfk.txt', 'C: > > \\\\\xcd\xee\xe2\xe0\xff \xef > > \xe0\xef\xea\xe0\\\xeb\xfb\xe2\xee\xe0\xeb\xee\xe0\xeb.txt'] > > > Why not "C:\\\\Новая папка\\ksdjfk.txt" and etc? > > glob returns a list; when you print a list, it uses repr() on its > elements. It *looks* strange, but has the right contents. See the above > modifications. > > -- > Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
how terminate console(not Ctrl-C)
Is it possible to interrupt loop (program) by pressing Q key like Ctrl- C? how can i hook user's keypress while program running? thnx -- http://mail.python.org/mailman/listinfo/python-list
Python ASP Error
I want continuie this topic http://groups.google.com/group/comp.lang.python/browse_thread/thread/6cc8f4154369abf2/df299ebaa5a2144c?hl=ru&lnk=st&q=Python+ASP+HTTP%2F1.1+500+Server+Error#df299ebaa5a2144c I have same problem Pythonwin's "Tools->Remote Trace Collector" show me: IOError: [Errno 13] Permission denied: 'C:\\WINDOWS\\TEMP\\gen_py\\2.5\ \__init__.py' pythoncom error: ERROR: server.policy could not create an instance. how solve this problem? -- http://mail.python.org/mailman/listinfo/python-list
SyntaxError: encoding problem: with BOM
i have 1.py in cp866 encoding: # -*- coding: cp866 -*- print ("ff") It's not work in Python 3.0 Error: File "", line 1 SyntaxError: encoding problem: with BOM what's wrong? -- http://mail.python.org/mailman/listinfo/python-list
Re: SyntaxError: encoding problem: with BOM
On 25 дек, 00:37, "Diez B. Roggisch" wrote: > NoName schrieb: > > > i have 1.py in cp866 encoding: > > > # -*- coding: cp866 -*- > > print ("ff") > > > It's not work in Python 3.0 > > Error: > > > File "", line 1 > > SyntaxError: encoding problem: with BOM > > > what's wrong? > > I can only guess, but just because you write the coding-header that > doesn't mean that the editor you use does actually *use* that encoding. > What I presume it does is to use utf-8, and write that stupid BOM > microsoft uses for denoting utf-8-content as first byte. Try using a > different editor, or alter it's settings to really use your desired > encoding. > > Diez I used Far Manager editor. and it *really* used cp866 I can print hex dump of source file. I don't want to use UTF-8 for py-file! -- http://mail.python.org/mailman/listinfo/python-list
Re: SyntaxError: encoding problem: with BOM
On 25 дек, 03:35, "Diez B. Roggisch" wrote: > NoName schrieb: > > > > > On 25 ÄÅË, 00:37, "Diez B. Roggisch" wrote: > >> NoName schrieb: > > >>> i have 1.py in cp866 encoding: > >>> # -*- coding: cp866 -*- > >>> print ("ff") > >>> It's not work in Python 3.0 > >>> Error: > >>> File "", line 1 > >>> SyntaxError: encoding problem: with BOM > >>> what's wrong? > >> I can only guess, but just because you write the coding-header that > >> doesn't mean that the editor you use does actually *use* that encoding. > >> What I presume it does is to use utf-8, and write that stupid BOM > >> microsoft uses for denoting utf-8-content as first byte. Try using a > >> different editor, or alter it's settings to really use your desired > >> encoding. > > >> Diez > > > I used Far Manager editor. and it *really* used cp866 > > I can print hex dump of source file. > > I don't want to use UTF-8 for py-file! > > How about you show us the python file in question? > > diez you can get it here http://slil.ru/26481345 -- http://mail.python.org/mailman/listinfo/python-list
Re: SyntaxError: encoding problem: with BOM
> NoName, Asking people to download a zip file from a website written in > a language and character set that they probably are not familiar with > is liable to make them rather nervous and not bother. It's not a good > way to ask for help. sorry:) Now i know where problem. But i dont know how to solve it. Error C:\Documents and Settings\Ra\Рабочий стол>11.py File "", line 1 SyntaxError: encoding problem: with BOM No error C:\Documents and Settings\Ra\Рабочий стол>python 11.py test Error when russian symbols in full path to py-script. Is it Python bug? or i need to modify some registry keys? OS: WinXP SP3 Russian. Python 3.0 (r30:67507, Dec 3 2008, 20:14:27) [MSC v.1500 32 bit (Intel)] on win32 -- http://mail.python.org/mailman/listinfo/python-list
Re: SyntaxError: encoding problem: with BOM
> It's a bug, please report it. I though we fixed all Windows path bugs > for 3.0 but apparently one slipped through. > > Christian It is too difficult for me. please help me=) -- http://mail.python.org/mailman/listinfo/python-list
Re: SyntaxError: encoding problem: with BOM
On 26 дек, 23:08, "Gabriel Genellina" wrote: > En Thu, 25 Dec 2008 11:55:16 -0200, NoName escribió: > > > Error > > > > C:\Documents and Settings\Ra\Рабочий стол>11.py > > File "", line 1 > > SyntaxError: encoding problem: with BOM > > > No error > > > > C:\Documents and Settings\Ra\Рабочий стол>python 11.py > > test > > > Error when russian symbols in full path to py-script. > > Is it Python bug? or i need to modify some registry keys? > > Yes, it's a bug. The encoding declaration may be anything, ascii, even an > inexistent codec will trigger the bug. Any non-ascii character in the > script name or path provokes then a SyntaxError when the script is > executed directly. > As a workaround, avoid using any Russian characters in directory names or > script file names, or invoke them always using "python xxx.py", not > directly. > > > OS: WinXP SP3 Russian. > > Python 3.0 (r30:67507, Dec 3 2008, 20:14:27) [MSC v.1500 32 bit > > (Intel)] on win32 > > My tests were on WinXP SP3 Spanish. > Seehttp://bugs.python.org/issue4747 > > -- > Gabriel Genellina Gabriel Genellina, thanks for bug report =) -- http://mail.python.org/mailman/listinfo/python-list