Re: [Tutor] Time - sum/difference

2005-10-24 Thread Jonas Melian
> >>> 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

Re: [Tutor] Time - sum/difference

2005-10-21 Thread Jonas Melian
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

[Tutor] Time - sum/difference

2005-10-20 Thread Jonas Melian
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

Re: [Tutor] iteration is overwriting the previous set value

2005-10-20 Thread Jonas Melian
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

Re: [Tutor] iteration is overwriting the previous set value

2005-10-20 Thread Jonas Melian
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

[Tutor] iteration is overwriting the previous set value

2005-10-19 Thread Jonas Melian
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

[Tutor] Sort a Set

2005-08-23 Thread Jonas Melian
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

[Tutor] Sort a list following the order of other list

2005-08-22 Thread Jonas Melian
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

[Tutor] nested loops

2005-08-22 Thread Jonas Melian
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

[Tutor] no rsplit

2005-08-21 Thread Jonas Melian
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

Re: [Tutor] Sorting by numbers

2005-08-21 Thread Jonas Melian
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

Re: [Tutor] Sorting by numbers

2005-08-21 Thread Jonas Melian
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

[Tutor] Sorting by numbers

2005-08-21 Thread Jonas Melian
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

[Tutor] os.access vs os.path.isfile

2005-08-20 Thread Jonas Melian
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

Re: [Tutor] iterating in the same line

2005-08-14 Thread Jonas Melian
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

[Tutor] iterating in the same line

2005-08-13 Thread Jonas Melian
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

[Tutor] Net mask in hex. to dec.

2005-08-10 Thread Jonas Melian
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

Re: [Tutor] skip some directories

2005-05-30 Thread Jonas Melian
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

[Tutor] skip some directories

2005-05-30 Thread Jonas Melian
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'

Re: [Tutor] Dudes with os.spawnlp

2005-05-29 Thread Jonas Melian
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 __

[Tutor] Dudes with os.spawnlp

2005-05-29 Thread Jonas Melian
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

[Tutor] os.spawnlp and os.spawnlpe

2005-05-29 Thread Jonas Melian
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

Re: [Tutor] UTF-8 by default

2005-05-29 Thread Jonas Melian
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

[Tutor] UTF-8 by default

2005-05-28 Thread Jonas Melian
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

Re: [Tutor] Data base in XML

2005-05-25 Thread Jonas Melian
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. _

Re: [Tutor] Exceptions and its error messages

2005-05-25 Thread Jonas Melian
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

[Tutor] Data base in XML

2005-05-25 Thread Jonas Melian
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!

[Tutor] Exceptions and its error messages

2005-05-25 Thread Jonas Melian
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

Re: [Tutor] Sorting a directory

2005-05-24 Thread Jonas Melian
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

[Tutor] Sorting a directory

2005-05-24 Thread Jonas Melian
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

Re: [Tutor] Checking and showing all errors before of exit

2005-05-23 Thread Jonas Melian
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

[Tutor] looking for a pattern in a lot of files

2005-05-22 Thread Jonas Melian
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]")

[Tutor] Checking and showing all errors before of exit

2005-05-21 Thread Jonas Melian
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

[Tutor] Exceptions for checking root, files

2005-05-21 Thread Jonas Melian
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

[Tutor] Comparing a string

2005-05-20 Thread Jonas Melian
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

[Tutor] kernel serie

2005-05-19 Thread Jonas Melian
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 -

[Tutor] Directory not empty :: Fast mode

2005-05-16 Thread Jonas Melian
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? ___