[FAQTS] Python Knowledge Base Update -- August 9th, 2000

Fiona Czuczman fiona at sitegnome.com
Wed Aug 9 06:33:37 EDT 2000


Hi All, 

The latest entries into http://python.faqts.com

cheers,

Fiona


## Unanswered Questions ########################################


-------------------------------------------------------------
in tkinter, how do you change a widget's parent?
http://www.faqts.com/knowledge-base/view.phtml/aid/5245
-------------------------------------------------------------
keith murphy



-------------------------------------------------------------
Can I script or access the internal of (X)Emacs with Python?
http://www.faqts.com/knowledge-base/view.phtml/aid/5254
-------------------------------------------------------------
Shae Erisson



## New Entries #################################################


-------------------------------------------------------------
Are circular package references allowed in Python?
http://www.faqts.com/knowledge-base/view.phtml/aid/5250
-------------------------------------------------------------
Fiona Czuczman
Alex Martelli

They're allowed.  E.g.:

D:\apy>python
Python 1.5.2 (#0, Apr 13 1999, 10:51:12) [MSC 32 bit (Intel)] on win32
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
>>> import uno
>>> uno.fun()
Pak!
>>> import due
>>> due.fun()
Poook!
>>>

Where the packages are:

D:\apy>type uno.py
import due

pippo='Poook!'

def fun():
    print due.pippo

D:\apy>type due.py
import uno

pippo='Pak!'

def fun():
    print uno.pippo

D:\apy>


-------------------------------------------------------------
How can I determine the number of characters in a string?
http://www.faqts.com/knowledge-base/view.phtml/aid/5251
-------------------------------------------------------------
Fiona Czuczman
Grant Edwards

len(s) will tell you how many elements (characters) are in string s.


-------------------------------------------------------------
Does the httplib support Keep-Alive Connection?
http://www.faqts.com/knowledge-base/view.phtml/aid/5253
-------------------------------------------------------------
Fiona Czuczman
The Dude

Keep-Alive is a HTTP/1.1 feature which is not support by Python 1.5.2
httplib.

You can get a HTTP/1.1 aware http module from
http://www.lyra.org/greg/python/


-------------------------------------------------------------
How would one go about preventing output of a program called through spawnv from getting printed to the console?
http://www.faqts.com/knowledge-base/view.phtml/aid/5255
-------------------------------------------------------------
Fiona Czuczman
j vickroy

>From pages 325,326 of "Python Programming on Win32" by Mark Hammond and 
Andy Robinson, it appears that the os.popen module or the win32pipe 
module may be of use.  Here are 2 examples from the book:

import os
file = os .popen ('echo Hello from Python')
file .read()
... 'Hello from Python'

import win32pipe
file = win32pipe. popen ('echo Hello from Python')
file .read()
... 'Hello from Python\012'

According to the book, os.popen does not work correctly within a GUI
application while win32pipe.popen does.

Hope this helps.


-------------------------------------------------------------
How can I convert an ascii formatted date into integer time in seconds since 1970?
http://www.faqts.com/knowledge-base/view.phtml/aid/5258
-------------------------------------------------------------
Fiona Czuczman
Stuart Ford, Aahz Maruch

Not a single function, but you can use the time.strptime function, and 
pass its result to the time.mktime function.  The only problem is that 
this doesn't work on Windows machines.

*nix Example:

TimeStr = "Jan 12 1999 20h23"
MyTime = int(time.mktime(time.strptime(TimeStr, "%b %d %Y %Hh%M")))

For a Windows Machine, you must parse the string yourself and use the
time.mktime function to return the Time integer.

Windows Example:

import re
import time
import string

def GetMonth(str):
    str = string.upper(str)
    if str == 'JAN':
        return 1
    elif str == 'FEB':
        return 2
    elif str == 'MAR':
        return 3
    elif str == 'APR':
        return 4
    elif str == 'MAY':
        return 5
    elif str == 'JUN':
        return 6
    elif str == 'JUL':
        return 7
    elif str == 'AUG':
        return 8
    elif str == 'SEP':
        return 9
    elif str == 'OCT':
        return 10
    elif str == 'NOV':
        return 11
    elif str == 'DEC':
        return 12
    else:
        return 0

def ParseDateString(TimeStr):
    match = r'(?P<month>\D*) (?P<day>\d*) (?P<year>\d*)
(?P<hour>\d*)h(?P<minute>\d*)'
    reMatch = re.compile(match)
    DateTimeFound = reMatch.search(TimeStr)
    DateTimeDict = DateTimeFound.groupdict()

    Year = string.atoi(DateTimeDict['year'])
    Month = GetMonth(DateTimeDict['month'])
    Day = string.atoi(DateTimeDict['day'])
    Hour = string.atoi(DateTimeDict['hour'])
    Minute = string.atoi(DateTimeDict['minute'])

    return int(time.mktime((Year, Month, Day, Hour, Minute, 0, 0, 0, 0))

-------

And yes, I know there are much easier ways to get the month digit with
a list or dictionary, but I wanted to be very basic in case any newbies 
were interested.

def GetMonth(str):
    months = ['JAN', 'FEB', 'MAR', 'APR', 'MAY', 'JUN', 'JUL', 
    'AUG', 'SEP', 'OCT', 'NOV', 'DEC'] 
    return months.index(string.upper(str) )+1

or just load up a dictionary and pull the value.

-------

If you're using Windows (and even if you're not), you may want to
consider M.A. Lemburg's mxDateTime package.  Look at
http://www.vex.net/parnassus to find it.







More information about the Python-list mailing list