Jeff Schwab wrote:[color=blue]
> What's the best way to generate a sequence of characters in Python? I'm
> looking for something like this Perl code: 'a' .. 'z' .[/color]
[color=blue][color=green][color=darkred]
>>> import string[/color][/color][/color]
[color=blue][color=green][color=darkred]
>>> print string.ascii_lo wercase[/color][/color][/color]
abcdefghijklmno pqrstuvwxyz
mensanator@aol. com wrote:[color=blue]
> Jeff Schwab wrote:
>[color=green]
>>What's the best way to generate a sequence of characters in Python? I'm
>>looking for something like this Perl code: 'a' .. 'z' .[/color]
>
>[color=green][color=darkred]
>>>>import string[/color][/color]
>
>[color=green][color=darkred]
>>>>print string.ascii_lo wercase[/color][/color]
>
> abcdefghijklmno pqrstuvwxyz[/color]
Thanks. Is there a good way to generate the characters dynamically?
Jeff Schwab wrote:[color=blue]
> mensanator@aol. com wrote:[color=green]
> > Jeff Schwab wrote:
> >[color=darkred]
> >>What's the best way to generate a sequence of characters in Python? I'm
> >>looking for something like this Perl code: 'a' .. 'z' .[/color]
> >
> >[color=darkred]
> >>>>import string[/color]
> >
> >[color=darkred]
> >>>>print string.ascii_lo wercase[/color]
> >
> > abcdefghijklmno pqrstuvwxyz[/color]
>
> Thanks. Is there a good way to generate the characters dynamically?[/color]
On Thu, 22 Sep 2005 23:26:58 -0400
Jeff Schwab <jeffrey.schwab @rcn.com> wrote:
[color=blue]
> What's the best way to generate a sequence of characters in Python?
> I'm looking for something like this Perl code: 'a' .. 'z' .[/color]
If you want arbitrary sequences, you may use something like:
Jeff Schwab wrote:
[color=blue]
> What's the best way to generate a sequence of characters in Python? I'm
> looking for something like this Perl code: 'a' .. 'z' .[/color]
[color=blue][color=green][color=darkred]
>>> import re
>>> def char_set(a_z, all_chars="".jo in(map(chr, range(256)))):[/color][/color][/color]
.... return re.compile("[%s]" % a_z).findall(al l_chars)
....[color=blue][color=green][color=darkred]
>>> for c in char_set("a-f0-9"): print c,[/color][/color][/color]
....
0 1 2 3 4 5 6 7 8 9 a b c d e f[color=blue][color=green][color=darkred]
>>> for c in char_set("\s"): print repr(c),[/color][/color][/color]
....
'\t' '\n' '\x0b' '\x0c' '\r' ' '
David> I realize CSV module has a sniffer but it is something that is
David> limited more or less to delimited files.
Sure. How about:
def sniff(fname):
if open(fname).rea d(4) == "<xml":
return "xml"
else:
# assume csv - use its sniffer to generate a dialect
return d
Of course, as the number of file formats grows, you'll need to expand the
logic. You can also run the file(1) command and see what it says. I seem
to recall someone asking about the equivalent to file(1) implemented in
Python awhile back.
Comment