To knowing if a directory isn't empty, I use:
dir_example = "/usr/foo/"
if glob.glob(os.path.join(dir_example, "*")):
...
But, as it has to expand all files, i'm supposed that it's a little slow
to simply knowing if a directory is empty.
Any improvement?
___
I want get the kernel serie, so 2.x only (2.6 or 2.4)
info_kernel = platform.release() # get the kernel version
info_kernel = '.'.join(info_kernel.split('.',2)[:2])
is there any way of get it in one line only?
Thanks in advance!
___
Tutor maillist -
I'm tryin compare a string with a value with style of pattern-matching.
string = 'i686'
if string == glob.glob(i?86):
This is fails because glob() is for listing files in a directory that
match a Unix ls-pattern
how make it?
Thanks!
___
Tutor maillis
Hi,
I never haven't worked with exceptions, and I'm a little confused.
In my programs I always build a function to check things as:
- The user that runned the script is root
- All the files and directories with whom I am going to work exist
- etc
else the program exits.
Does this checks can be
Is there any way of checking all possible errors, show you all error
messages, and then exit.
If i use :: sys.exit("error message") :: it only shows this error
message before of exit.
Thanks in advance!
___
Tutor maillist - Tutor@python.org
http://mai
I've to looking for a pattern ('locale for') in a lot of files
(/dir/*_[A-Z][A-Z])
it's goes ok
any improvement about this code?
how print the actual file?
could i add an exception? by if there aren't files
for line in fileinput.input(glob.glob(os.path.join
(dir_locales, "*_[A-Z][A-Z]")
Kent Johnson wrote:
>
>>Is there any way of checking all possible errors, show you all error
>>messages, and then exit.
>
> I don't understand your question. Can you give an example of what you would
> like to do?
>
The idea was check all exceptions before of exit. I made it :)
flag_error = Fa
Hi all,
I have to working with the files lines in this directory:
:::
dir_locales = "/usr/share/i18n/locales/"
for line in fileinput.input(glob.glob(os.path.join\
(dir_locales, "*_[A-Z][A-Z]"))):
...
:::
The problem is that the directory otuput is:
aa_DJ
aa_ER
aa_ET
af_ZA
...
and
Kent Johnson wrote:
>>and i would sort this files by the 2 last letters, so:
>
> The sort() method of a mutable sequence is very powerful. Docs for it are
> here:
> http://docs.python.org/lib/typesseq-mutable.html
>
> The key= parameter of sort() allows you to provide a function which, given a
Hi,
How to know all the exceptions that there are? (i.e. OSError, ImportError)
And all error messages of each exception? (i.e. err_o.strerror,
err_o.filename)
Thanks in advance!
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/list
Hi all,
I'm going to build a little data base in XML, with information about
localization for each country.
Then, I'm in dude of using xml.sax (built in python) or elementtree.
Which do you recommend to me?
And is it necessary build a DTD or Schema file?
Thanks in advance!
Kent Johnson wrote:
> Jonas Melian wrote:
>> How to know all the exceptions that there are? (i.e. OSError, ImportError)
>
> Some library modules define their own exceptions such as socket.error so
> the above is not a complete
> list of exceptions defined in the standard d
Kent Johnson wrote:
>>I'm going to build a little data base in XML, with information about
>>localization for each country.
>
> Why XML? You could use pickle or CSV or a real database...
>
I have choosed XML because it's designed as a universal data exchange
format.
_
Hi all,
I'm working with an XML file, and i want to write in UTF-8
How write by default in UTF-8 instead of ASCII?
And I want not to use: print u'String'
Thanks in advance!
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo
Kent Johnson wrote:
>>How write by default in UTF-8 instead of ASCII?
>
>
> How are you writing the file? What encoding is your data originally?
>
For writing the XML file:
>>ElementTree.ElementTree(root).write("file.xml")
The source encoding is UTF-8 ( # -*- coding: utf-8 -*- )
But I also w
Hi,
which is the difference between os.spawnlp and os.spawnlpe?
With an example, please. I don't understand it.
Thanks!
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
This code run 'X -configure' using $PATH for looking for its path
::
try:
#retcode = call("X" + " -configure", shell=True) # 2.4
code_return = os.spawnlp(os.P_WAIT, "X", "X", "-configure")
if retcode < 0:
print >>sys.stderr, "Child was terminated by signal", -retcode
els
Kent Johnson wrote:
> I don't know the answer to your question, but I wonder what you mean by
> 'dudes'. You use that word a
> lot and it never makes sense to me; I suspect you mistake its meaning.
>
> Can you find another word?
>
Oh sorry,
s/dudes/doubts
__
Hi,
I'm trying to working with some directories only
import os
dirName = "/usr/share/fonts/"
dirBase = ['misc','TTF','Type1','CID','100dpi','75dpi'] # directories to
skip
for root, dirs, files in os.walk(dirName):
for end in dirBase:
if root.endswith(end):
print 'skiped'
Danny Yoo wrote:
>>I'm trying to working with some directories only
>>
>>import os
>>dirName = "/usr/share/fonts/"
>>dirBase = ['misc','TTF','Type1','CID','100dpi','75dpi'] # directories to
>>skip
>>
>>for root, dirs, files in os.walk(dirName):
>>for end in dirBase:
>>if root.endswith(e
Hi,
I get the netmask (mask="0xff00") from ifconfig in openbsd, and i
would convert it to decimal (255.255.255.0)
I think that socket module doesn't help on this. So I'll have to make
something as this for separate 'mask'
[s[i:i+2] for i in range(0, len(s), 2)]
then i could use int('', 16
I would check 3 words at the starting of a line
s=['foo','bar','qwe']
if ln.startswith(s): (this is bad)
what is the best way for making it?
if max(map(ln.startswith,s)):
or
reduce(lambda m,n:m or n, map(ln.startswith, s))
Thanks!
___
Tutor maillis
I'm trying match the lines that starting with someone variable in 's'
These sentences:
if max(map(ln.startswith,s)):
reduce(lambda m,n:m or n, map(ln.startswith, s)):
were said me in #python for this proposal.
Alan G wrote:
> Sorry Jonas,
>
> I don't understand what you are trying to do at all
os.access is better/fast that os.path.isfile for checking if exist a file?
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
From an input as this:
Standard timing 0: 85 Hz, 640x480
Standard timing 1: 85 Hz, 800x600
Standard timing 2: 85 Hz, 1024x768
Standard timing 3: 85 Hz, 1280x1024
Standard timing 4: 70 Hz, 1600x1200
Standard timing 5: 60 Hz, 1920x1440
I want to get columns 3 and 5 for sort them from mayor mo mino
Solution:
modes.sort(key=lambda item: int(item[1].split('x')[0])) # 2.4
modes.sort(lambda x, y: cmp(int(x[1].split('x')[0]),
int(y[1].split('x')[0]))) #2.3.5
Jonas Melian wrote:
> From an input as this:
>
>Standard timing 0: 85 Hz, 640x480
>Standard t
tion:
>modes.sort(key=lambda item: int(item[1].split('x')[0])) # 2.4
>modes.sort(lambda x, y: cmp(int(x[1].split('x')[0]),
>int(y[1].split('x')[0]))) #2.3.5
>
>Jonas Melian wrote:
>
>
>
>>From an input as this:
>>
>>Stand
v = "64x43x12" -> '64x43', '12'
How split it by the las 'x'?
In 2.4 it could be used rsplit("x",1)
but i've 2.3.5
Is there another way of splitting a string from the end?
___
Tutor maillist - [EMAIL PROTECTED]
http://mail.python.org/mailman/listinf
Is there any way more efficient for run a nested loop?
--
for a in list_a:
for b in list_b:
if a == b: break
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor
best = [ [1024, 768], [800, 600], [640, 480] ] (it's larger)
modes = [
(24, [1280, 1024]),
(24, [1024, 768]),
(24, [640, 480]),
(16, [1600, 1200]),
(16, [1280, 1024]),
(15, [320, 200]),
]
I want to create a list with ALL elements of 'modes', but following the
order of list 'best' (if exist the
I get a list of repeated numbers [24, 24, 24, 16, 16, 15, 15 ]
Is possible get it without repeated numbers, without using set()?
If I use set, then the list is unsorted and i cann't sorting it.
For get the values i use:
[x[0] for x in cardTmp]
or:
from itertools import imap
for i in imap(lamb
def _pre_save(self):
for field in [self.name, self.native_name]:
if not field.istitle():
#print field.title()
field = field.title()
The change I try to do there (field = field.title()) is not being applied
I changed code so that you do 'self.foo = bar' statement
bob wrote:
> At 04:16 PM 10/19/2005, Jonas Melian wrote:
>
>> def _pre_save(self):
>> for field in [self.name, self.native_name]:
>> if not field.istitle():
>> #print field.title()
>> field = field.title()
>>
>> T
Your code is correct. Thanks
I understood it. 'field' is a local variable inner that loop.
Respect to a related matter, a should be '42'
Danny Yoo wrote:
>On Thu, 20 Oct 2005, Jonas Melian wrote:
>
>
>
>Hi Jonas,
>
>
>Do you understand why it is
I would get the local time of a country, using UTC (Universal Time
Coordinated) and DST (Daylight SavingTime) of that country.
An example, utc time -02:30 and dst +1 :
country_utc = datetime.time(2,30)
isUTCNegative = True
dst = datetime.time(1,0)
Now I would the difference of both times.
-02:3
I wanted to sum two time values:
-02:30
+01:00
--
-01:30
I found one solution:
>>> time_local = dt.time(2,30)
>>> time_str = str(time_local).split(':')
Now I'll can get the first value, convert to integer and sum it.
Kent Johnson wrote:
>Jon
> >>> sleep(5)
> >>> time.sleep(5)
> >>> late = time.time()
> >>> print late - early
> 5.7889997959
> >>>
>
>
> Jonas Melian wrote:
>
>> I would get the local time of a country, using UTC (Universal Time
>> Coor
37 matches
Mail list logo