Re: sed/awk/perl: How to replace all spaces each with an underscore that occur before a specific string ?

2009-08-22 Thread Jan Kaliszewski
22-08-2009 o 20:11:32 bolega gnuist...@gmail.com wrote: sed/awk/perl: How to replace all spaces each with an underscore that occur before a specific string ? $ rm -rf /home/bolega ; python -c 'for i in xrange(1000): print I will never crosspost senselessly.' ;~] -- Jan Kaliszewski (zuo

Re: string literal vs string variable

2009-08-22 Thread Jan Kaliszewski
to as 'variables', regarding other languages' terminology). Cheers, *j -- Jan Kaliszewski (zuo) z...@chopin.edu.pl -- http://mail.python.org/mailman/listinfo/python-list

Re: Items inheriting attributes from its container?

2009-08-22 Thread Jan Kaliszewski
?). Otherwise, as Stephen noted, you should subclass set rather than list. Cheers, *j -- Jan Kaliszewski (zuo) z...@chopin.edu.pl -- http://mail.python.org/mailman/listinfo/python-list

Re: Items inheriting attributes from its container?

2009-08-22 Thread Jan Kaliszewski
in playerdata: self.append(Player(data)) -- Jan Kaliszewski (zuo) z...@chopin.edu.pl -- http://mail.python.org/mailman/listinfo/python-list

Re: #elements of seq A in seq B

2009-08-20 Thread Jan Kaliszewski
a = set(a) n = sum(item in a for item in b) Why set? Does it matter if I say that items in A are already unique? Sets are hash-based, so it's (most probably) far more efficient for sets than for sequences (especially if we say about big/long ones). Regards, *j -- Jan Kaliszewski

Re: difference between 2 arrays

2009-08-19 Thread Jan Kaliszewski
19-08-2009 o 10:56:20 Michel Claveau - MVPenleverLesX_XXmcX@xmclavxeaux.com wrote: (envoyé via news:\\news.wanadoo.fr\comp.lang.python) Hi! See the module sets No, see the builtin set type. Module sets is deprecated (removed in Py 3.x) -- Jan Kaliszewski (zuo) z...@chopin.edu.pl -- http

Re: Dictionary from a list

2009-08-19 Thread Jan Kaliszewski
])) Or (for long lists, when memory becomes expensive): dict(li[i:i+2] for i in xrange(0, len(li), 2)) Or probably better: from itertools import islice, izip dict(izip(islice(li, 0, None, 2), islice(li, 1, None, 2))) Cheers, *j -- Jan Kaliszewski (zuo) z...@chopin.edu.pl -- http

Re: #elements of seq A in seq B

2009-08-19 Thread Jan Kaliszewski
element of A (separately) in B... Hm, maybe something like this: # result as a dict {element of A: how many occurences in B, ...} dict((element, B.count(element)) for element in A) If you mean: to count non overlaping occurences of string A in B -- simply: B.count(A) Regards, *j -- Jan

Re: Dictionary from a list

2009-08-19 Thread Jan Kaliszewski
20-08-2009 o 02:05:57 Jan Kaliszewski z...@chopin.edu.pl wrote: Or probably better: from itertools import islice, izip dict(izip(islice(li, 0, None, 2), islice(li, 1, None, 2))) Or similarly, perhaps more readable: iterator = iter(li) dict((iterator.next(), iterator.next

Re: Code formatting question: conditional expression

2009-08-18 Thread Jan Kaliszewski
None) I'd use conditional expression only (rather) in situation when the first expression-part was 'common' and the other (after else) was 'rare'. Cheers, *j -- Jan Kaliszewski (zuo) z...@chopin.edu.pl -- http://mail.python.org/mailman/listinfo/python-list

Re: Inheriting dictionary

2009-08-18 Thread Jan Kaliszewski
curiosity) :-) Regards, *j -- Jan Kaliszewski (zuo) z...@chopin.edu.pl -- http://mail.python.org/mailman/listinfo/python-list

Re: define class over 2 files

2009-08-18 Thread Jan Kaliszewski
that some other solution would be better (e.g. inheritance). Cheers, *j -- Jan Kaliszewski (zuo) z...@chopin.edu.pl -- http://mail.python.org/mailman/listinfo/python-list

Re: How to create functors?

2009-08-18 Thread Jan Kaliszewski
want to avoid using a def if possible. But what for? Usualy def is more readable than lambda and it's not worth to lose readibility just to save a few keystrokes. Cheers, *j -- Jan Kaliszewski (zuo) z...@chopin.edu.pl -- http://mail.python.org/mailman/listinfo/python-list

Re: Inheriting dictionary

2009-08-18 Thread Jan Kaliszewski
examples like above. *j -- Jan Kaliszewski (zuo) z...@chopin.edu.pl -- http://mail.python.org/mailman/listinfo/python-list

Re: How to create functors?

2009-08-18 Thread Jan Kaliszewski
it (see: http://docs.python.org/3.1/whatsnew/3.0.html ). Regards, *j -- Jan Kaliszewski (zuo) z...@chopin.edu.pl -- http://mail.python.org/mailman/listinfo/python-list

Re: How do I convert an iterator over bytes into a str?

2009-08-18 Thread Jan Kaliszewski
(and even recommended over s=s+t or s+=t, when applicable -- see: http://docs.python.org/library/stdtypes.html#sequence-types-str-unicode-list-tuple-buffer-xrange). Cheers, *j -- Jan Kaliszewski (zuo) z...@chopin.edu.pl -- http://mail.python.org/mailman/listinfo/python-list

Re: Scope and classes

2009-08-18 Thread Jan Kaliszewski
' scope. The only ways to reach Abc's attribute 'message' from that method are: * 'Abc.message' * 'self.__class__.message' * 'self.message' (unless there is an instance attribute 'message' which overrides the class attribute). Cheers, *j -- Jan Kaliszewski (zuo) z...@chopin.edu.pl -- http

Re: Scope and classes

2009-08-18 Thread Jan Kaliszewski
19-08-2009 o 02:10:58 Jan Kaliszewski z...@chopin.edu.pl wrote: The only ways to reach Abc's attribute 'message' from that method are: * 'Abc.message' * 'self.__class__.message' * 'self.message' (unless there is an instance attribute 'message' which overrides the class attribute

Re: Raw Strings with Variables

2009-08-18 Thread Jan Kaliszewski
:\moo, C:\supermoo print ', '.join('%s' % item for item in arrPlaces) Output: 'C:\moo', 'C:\supermoo' Cheers, *j -- Jan Kaliszewski (zuo) z...@chopin.edu.pl -- http://mail.python.org/mailman/listinfo/python-list

Re: Splitting a string into substrings of equal size

2009-08-15 Thread Jan Kaliszewski
strings (for sure most common case) it's ok: simple and clear. But for huge ones, it's better not to materialize additional list for the string -- then pure-iterator-sollutions would be better (like Gabriel's or mine). Cheers, *j -- Jan Kaliszewski (zuo) z...@chopin.edu.pl -- http://mail.python.org

Re: Why is unpacking of tuples only allowed when there's 1 tupple ?

2009-08-15 Thread Jan Kaliszewski
# than len(Polynome) # of arguments -- Jan Kaliszewski (zuo) z...@chopin.edu.pl -- http://mail.python.org/mailman/listinfo/python-list

Re: Splitting a string into substrings of equal size

2009-08-14 Thread Jan Kaliszewski
), *repeated_iterator) return sep.join(itertools.chain((text[:beg],), strings)) print separate('12345678') print back_separate('12345678') http://docs.python.org/library/itertools.html#recipes was the inspiration for me (especially grouper). Cheers, *j -- Jan Kaliszewski (zuo) z...@chopin.edu.pl

Re: Splitting a string into substrings of equal size

2009-08-14 Thread Jan Kaliszewski
15-08-2009 Jan Kaliszewski z...@chopin.edu.pl wrote: 15-08-2009 candide cand...@free.invalid wrote: Suppose you need to split a string into substrings of a given size (except possibly the last substring). I make the hypothesis the first slice is at the end of the string. A typical example

Re: i Don't get why it makes trouble

2009-08-13 Thread Jan Kaliszewski
placeholder but it wont format the string j must be a tuple -- so either define it as (u'Tata', u'Oriovac', u'PrimorskoGoranska', u'hrvatska', u'Kuna') or when using it, wrap it with tuple() constructor: h = ... % tuple(j) -- Jan Kaliszewski (zuo) z...@chopin.edu.pl -- http

Re: i Don't get why it makes trouble

2009-08-13 Thread Jan Kaliszewski
, v.id_valuta FROM ulica as u, opcina as o, zupanija as \ ... z, drzava as d, valuta as v WHERE u.naziv = '{0}' AND o.naziv = \ ... '{1}' AND z.naziv = '{2}' AND d.naziv = '{3}' AND v.naziv = '{4}'\ ... .format(*j) Cheers, *j -- Jan Kaliszewski (zuo) z...@chopin.edu.pl -- http://mail.python.org/mailman

Re: With or without leading underscore...

2009-08-10 Thread Jan Kaliszewski
. isinstance(foo, YourType). Cheers, *j -- Jan Kaliszewski (zuo) z...@chopin.edu.pl -- http://mail.python.org/mailman/listinfo/python-list

Re: Need help in configuration for TimedRotatingFileHandler

2009-08-09 Thread Jan Kaliszewski
' special character) and not '\\r' (which would mean '\' char + 'r' char). Regards, *j -- Jan Kaliszewski (zuo) z...@chopin.edu.pl -- http://mail.python.org/mailman/listinfo/python-list

Re: Bug or feature: double strings as one

2009-08-09 Thread Jan Kaliszewski
09-08-2009 r rt8...@gmail.com wrote: On Aug 8, 12:43 pm, Jan Kaliszewski z...@chopin.edu.pl wrote: 08-08-2009 Steven D'Aprano st...@remove-this-cybersource.com.au wrote: ...(snip) I use it very often, e.g.:          afunction('quite long string %s quite long string

Re: Bug or feature: double strings as one

2009-08-08 Thread Jan Kaliszewski
, variable2, variable3)) (Note that multiline-'''-strings are usless in such cases). *j -- Jan Kaliszewski (zuo) z...@chopin.edu.pl -- http://mail.python.org/mailman/listinfo/python-list

Re: remove last 76 letters from string

2009-08-05 Thread Jan Kaliszewski
: print nucleotides, ' foo bar length=76' print nucleotides, seq[-76] Cheers, *j -- Jan Kaliszewski (zuo) z...@chopin.edu.pl -- http://mail.python.org/mailman/listinfo/python-list

Re: remove last 76 letters from string [sorry, errata]

2009-08-05 Thread Jan Kaliszewski
: print nucleotides, ' foo bar length=76' print nucleotides, seq[-76] Cheers, *j -- Jan Kaliszewski (zuo) z...@chopin.edu.pl -- http://mail.python.org/mailman/listinfo/python-list

Re: boolean OR gotcha

2009-08-04 Thread Jan Kaliszewski
. The last is ok: None != 0. *j -- Jan Kaliszewski (zuo) z...@chopin.edu.pl -- http://mail.python.org/mailman/listinfo/python-list

Re: Obtaining Python version

2009-08-03 Thread Jan Kaliszewski
are integers; the release level is 'alpha', 'beta', 'candidate', or 'final'. The version_info value corresponding to the Python version 2.0 is (2, 0, 0, 'final', 0). http://docs.python.org/library/sys.html#sys.version_info Cheers, *j -- Jan Kaliszewski (zuo) z...@chopin.edu.pl -- http

Re: socket send

2009-07-30 Thread Jan Kaliszewski
is the problem? *j -- Jan Kaliszewski (zuo) z...@chopin.edu.pl -- http://mail.python.org/mailman/listinfo/python-list

Re: socket send

2009-07-30 Thread Jan Kaliszewski
(b'What makes you think she is a witch?') # but not this way b'What makes you think she is a witch?' [^ note this] Cheers, *j -- Jan Kaliszewski (zuo) z...@chopin.edu.pl -- http://mail.python.org/mailman/listinfo/python-list

Re: Confessions of a Python fanboy

2009-07-30 Thread Jan Kaliszewski
but isn't sexy (and tends to lower readability imo). I don't see any real limitation. What's wrong in: for localVar in container: block And ruby's container.each is very similar to Python's iter() *j -- Jan Kaliszewski (zuo) z...@chopin.edu.pl -- http://mail.python.org/mailman/listinfo

Re: Printing with colors in a portable way

2009-07-30 Thread Jan Kaliszewski
[used_term] print('Some text, {colors.blue}Something in blue, ' '{colors.red}And now in red.').format(colors=colors) Regards, *j -- Jan Kaliszewski (zuo) z...@chopin.edu.pl -- http://mail.python.org/mailman/listinfo/python-list

Re: Does underscore has any special built-in meaningin Python ?

2009-07-29 Thread Jan Kaliszewski
/reference/lexical_analysis.html#reserved-classes-of-identifiers * http://docs.python.org/reference/datamodel.html#object.__del__ (in the the red Warning frame) -- Jan Kaliszewski (zuo) z...@chopin.edu.pl -- http://mail.python.org/mailman/listinfo/python-list

Re: set variable to looping index?

2009-07-29 Thread Jan Kaliszewski
= [] for name in filenames: results.append(some_function(name)) If filenames were generated according to a particular pattern, you can mimic that pattern and generate filenames list using list-comprehension, e.g.: filenames = ['file{nr}.txt'.format(nr=nr) for nr in range(13)] Chreers, *j -- Jan

Re: set variable to looping index?

2009-07-29 Thread Jan Kaliszewski
Me wrote: filenames = p'foo', 'bar', baz'] Sorry, should be of course: filenames = ['foo', 'bar', baz'] *j -- Jan Kaliszewski (zuo) z...@chopin.edu.pl -- http://mail.python.org/mailman/listinfo/python-list

Re: need help using Tkinter

2009-07-28 Thread Jan Kaliszewski
by something else, can you please give me some guidance? What operating system do you use? *j -- Jan Kaliszewski (zuo) z...@chopin.edu.pl -- http://mail.python.org/mailman/listinfo/python-list

Re: Convert raw binary file to ascii

2009-07-27 Thread Jan Kaliszewski
Hello Friends, It's my first post to python-list, so first let me introduce myself... * my name is Jan Kaliszewski, * country -- Poland, * occupation -- composer (studied in F. Chopin Academy of Music @Warsaw) and programmer (currently in Record System company

Re: Gracefully exiting CLI application

2009-07-27 Thread Jan Kaliszewski
27-07-2009 o 22:35:01 David 71da...@libero.it wrote: I am writing a command line application, and I need to perform some cleaning on exit even if the process is killed. How can I do that with python? See: http://docs.python.org/library/signal.html Cheers, *j -- Jan Kaliszewski (zuo) z

Re: Gracefully exiting CLI application

2009-07-27 Thread Jan Kaliszewski
a good idea to combine these two techniques (i.e. signal handlers call sys.exit(), then sys.exitfunc/or function registered with atexit does the actual cleaning actions). *j -- Jan Kaliszewski (zuo) z...@chopin.edu.pl -- http://mail.python.org/mailman/listinfo/python-list

[issue6575] Can't download docs

2009-07-26 Thread Jan Kaliszewski
New submission from Jan Kaliszewski z...@chopin.edu.pl: http://docs.python.org/3.1/download.html (available both with 'Download these documents' link @docs and 'Download Current Python 3.1 Documentation' link @http://www.python.org/doc/) doesn't contain links to packed docs, but text for dev

[issue6576] re docs: wrong link targets

2009-07-26 Thread Jan Kaliszewski
New submission from Jan Kaliszewski z...@chopin.edu.pl: Some of links in re docs should lead to RegexObject.match()| RegexObject.search() method but lead to re.match()|re.search() module function. These are the places in 2.6 docs (in 2.7-3.2 versions' you'll find the bug in analogous places

[issue6577] Links wrongly targeting to builtin functions' instead of module functions/methods

2009-07-26 Thread Jan Kaliszewski
New submission from Jan Kaliszewski z...@chopin.edu.pl: The problem can be found in many places in docs -- tipically, where there is a function/method with name identical to builtin name (or sometimes to another function/method within the same module -- see: #6575): links leads to te latter

[issue6578] 2 problems with 'Docs for other versions' section on left HTML docs sidebar

2009-07-26 Thread Jan Kaliszewski
New submission from Jan Kaliszewski z...@chopin.edu.pl: * In 2.6 the content of that section isn't up to date (3.1 is descripted as 'in development') * In 3.0 there is no that section. -- messages: 90945 nosy: zuo severity: normal status: open title: 2 problems with 'Docs for other

[issue6578] 2 problems with 'Docs for other versions' section on left HTML docs sidebar

2009-07-26 Thread Jan Kaliszewski
Changes by Jan Kaliszewski z...@chopin.edu.pl: -- assignee: - georg.brandl components: +Documentation nosy: +georg.brandl ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue6578

[issue6579] No update about automatic numbering of fields in format strings (e.g. 'A {} with {} buttocks')

2009-07-26 Thread Jan Kaliszewski
New submission from Jan Kaliszewski z...@chopin.edu.pl: As we can read in http://docs.python.org/3.1/whatsnew/3.1.html#other- language-changes: The fields in format() strings can now be automatically numbered: 'Sir {} of {}'.format('Gallahad', 'Camelot') 'Sir Gallahad of Camelot

[issue4947] sys.stdout fails to use default encoding as advertised

2009-05-12 Thread Jan Kaliszewski
Jan Kaliszewski z...@chopin.edu.pl added the comment: The matter had been discussed (and not once...), IMO without satisfactory conclusion -- see: * http://bugs.python.org/issue612627 (the feature added) * http://bugs.python.org/issue1214889 (another feature rejected) * http://bugs.python.org

[issue4947] sys.stdout fails to use default encoding as advertised

2009-05-12 Thread Jan Kaliszewski
Jan Kaliszewski z...@chopin.edu.pl added the comment: PS. The main problem is not a lack of feature but that inconsistency, and that's not documented if File type docs: print my_file, my_unicode # - is encoded with my_file.encoding my_file.write(my_unicode) # - is encoded

[issue4947] sys.stdout fails to use default encoding as advertised

2009-05-12 Thread Jan Kaliszewski
Jan Kaliszewski z...@chopin.edu.pl added the comment: s / if File / in File s / -- works # - is encoded with my_file.encoding / # - is encoded with sys.stdout.encoding (sorry, too little sleep) -- ___ Python tracker rep...@bugs.python.org http

[issue4947] sys.stdout fails to use default encoding as advertised

2009-05-12 Thread Jan Kaliszewski
Changes by Jan Kaliszewski z...@chopin.edu.pl: -- assignee: - georg.brandl components: +Documentation nosy: +georg.brandl ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue4947

[issue4764] open('existing_dir') - IOError instance's attr filename is None

2008-12-28 Thread Jan Kaliszewski
New submission from Jan Kaliszewski z...@chopin.edu.pl: Py2.4 and 2.5 (and probably other 2.x releases too): try: f=open('existing_dir') ... except IOError, exc: print exc.filename ... None (expected result: existing_dir) Py3.0 (and possibly 3.1 too): try: f=open('existing_dir') ... except

<    1   2