Re: how to call a function for evry 10 secs

2011-07-01 Thread Rune Strand
from threading import Timer def Func_to_call: do_stuff() my_timer = Timer(10, Func_to_call) my_timer.start() -- http://mail.python.org/mailman/listinfo/python-list

Adding a __filename__ predefined attribute to 2.5?

2005-10-11 Thread Rune Strand
Is it an idea to include a new __filename__ predefined attribute to 2.5, so that __file__ contains the entire path to the module, and __filename__ only the name of the module? For instance it's useful to include a not-static reference to the filename in a scripts usage() section and it's cumbersom

Re: Adding a __filename__ predefined attribute to 2.5?

2005-10-12 Thread Rune Strand
I Steve, I know it's several ways to isolate the filename. I just want to avoid the overhead of importing sys or os to achieve it. Currently I have this in my scripts: __filename__ = __file__.replace('\\', '/').rsplit('/', 1)[-1] -- http://mail.python.org/mailman/listinfo/python-list

Re: Adding a __filename__ predefined attribute to 2.5?

2005-10-12 Thread Rune Strand
Excuse me, do you suffer from a bad hair-day? I didn't say it is platform independant. It's ok for my use on Linux and Windows. If you cannot imagine any other usecase for a __filename__ attribute, that's your problem, not mine. -- http://mail.python.org/mailman/listinfo/python-list

Re: Adding a __filename__ predefined attribute to 2.5?

2005-10-12 Thread Rune Strand
> those modules are already imported when Python gets to your code, so > the only "overhead" you're saving is a little typing. I don't understand this. Could you please elaborate? - if sys or os are not imported for any other causes how are they already imported? Maybe I'm wrong here, and accessi

Re: Adding a __filename__ predefined attribute to 2.5?

2005-10-12 Thread Rune Strand
Ok, Alex. I know a good explanation when I see one. Thanks! -- http://mail.python.org/mailman/listinfo/python-list

Re: Adding a __filename__ predefined attribute to 2.5?

2005-10-13 Thread Rune Strand
I've read a lot of your comments the last years. Your friendliness always strikes me. -- http://mail.python.org/mailman/listinfo/python-list

Re: reading a list from a file

2005-06-20 Thread Rune Strand
But iif it are many lists in the file and they're organised like this: ['a','b','c','d','e'] ['a','b','c','d','e'] ['A','B','C','D','E'] ['X','F','R','E','Q'] I think this'll do it data = open('the_file', 'r').read().split(']') lists = [] for el in data: el = el.replace('[', '').strip()

Re: reading a list from a file

2005-06-20 Thread Rune Strand
:-/ You're right! -- http://mail.python.org/mailman/listinfo/python-list

Re: Better console for Windows?

2005-06-27 Thread Rune Strand
Brett Hoerner wrote: > Another problem with cmd.com is when I run IPython, if I have an error, > or tab or anything, I get the speaker beep (ala linux) but I can't find > a way to turn it off. This is a huge problem because I cannot disable > my system speaker on my laptop (not even in BIOS like

Re: Better console for Windows?

2005-06-27 Thread Rune Strand
Annoyed by windows? Check this URL: http://www.annoyances.org/exec/show/category01 ;-) -- http://mail.python.org/mailman/listinfo/python-list

Re: Which kid's beginners programming - Python or Forth?

2005-06-27 Thread Rune Strand
BORT wrote: > Please forgive me if this is TOO newbie-ish. > > I am toying with the idea of teaching my ten year old a little about > programming. I started my search with something like "best FREE > programming language for kids." After MUCH clicking and high-level > scanning, I am looking at

Re: How to find Windows "Application data" directory??

2005-06-28 Thread Rune Strand
You have the environment variable APPDATA. You can access it with os.environ(). -- http://mail.python.org/mailman/listinfo/python-list

Re: File parser

2005-08-29 Thread Rune Strand
It's not clear to me from your posting what possible order the tags may be inn. Assuming you will always END a section before beginning an new, eg. it's always: A some A-section lines. END A B some B-section lines. END B etc. And never: A some A-section lines. B some B-section lines. END B

Re: execute commands independantly

2005-09-06 Thread Rune Strand
Mike Tammerman wrote: > I am trying to execute an executable or a pyton script inside my > program. I looked at the subprocess and os module. But all the > functions in these modules blocks my application. What I want to do is > run the subprocess without any concern. I don't care of its return ty

Re: "week-year" conversion to date

2005-09-14 Thread Rune Strand
year = '2005' week = 50 weekday = 1 # Monday is 1 time_expr = '%s, %s, %s' % (year, week, weekday) time_struct = time.strptime(time_expr, "%Y, %W, %w") print time.strftime("%Y%m%d", time_struct) But the datetime module may have an easier way -- http://mail.python.org/mailman/listinfo/python-li

Re: Some advice on startingout with python.

2005-09-14 Thread Rune Strand
It's not about GUI, but it's a good book. It's both online and printed: http://diveIntoPython.org -- http://mail.python.org/mailman/listinfo/python-list

Re: import hook

2006-06-11 Thread Rune Strand
Jeremy Sanders wrote: > Hi - Is it possible to override the import process so that if in my program > I do (...) > > Any ideas? Why not handle the foo.bar/version string separately and just append the resulting path to sys.path? -- http://mail.python.org/mailman/listinfo/python-list

Screen capturing on Windows

2006-06-13 Thread Rune Strand
Is it possible by use of pyWin32 or ctypes to make a screen capture of an inactive, or a hidden window if the hwnd/WindowName/ClassName is known? I've seen dedicated screen capture software do this. While PIL.ImageGrab.grab() is excellent, it will only capture the foreground of the desktop. I've t

Re: a string problem

2006-06-13 Thread Rune Strand
[EMAIL PROTECTED] wrote: > hi > > if i have a some lines like this > a ) "here is first string" > b ) "here is string2" > c ) "here is string3" > > When i specify i only want to print the lines that contains "string" ie > the first line and not the others. If i use re module, how to compile > the

Re: Looping through a file a block of text at a time not by line

2006-06-14 Thread Rune Strand
Rosario Morgan wrote: > Hello > > Help is great appreciated in advance. > > I need to loop through a file 6000 bytes at a time. I was going to > use the following but do not know how to advance through the file 6000 > bytes at a time. > > file = open('hotels.xml') > block = file.read(6000) > newb

Re: Python is fun (useless social thread) ;-)

2006-06-17 Thread Rune Strand
In 2002, I was in need of a multi-platform language. My choice became Python, in spite of friends fiercly defending Perl and some interesting Slashdot-articles on Ruby. But back on university, I met a very, very pretty C++ girl who said many favourable things about Python. She never became mine, bu

Re: Tetris

2006-06-18 Thread Rune Strand
Devon G. Parks wrote: > I've been searching google and this group for a while now for a good > tutorial on making a Tetris-style game in Python. I hear Tetris is a > good starting point, and although I am fairly new to programming I > think I would learn best if I had some code to experiment with

Re: Beginner Programmer Question

2006-06-26 Thread Rune Strand
> > I am doing alot of reading, and the problem didnt come with an answer. > I dont understand how to get it to continually input numbers and add > all those together Use while, raw_input, sys.argv[1] and int() and break the loop when the sum is above 100. ;-) -- http://mail.python.org/mailman/

Re: Beginner Programmer Question

2006-06-26 Thread Rune Strand
[EMAIL PROTECTED] wrote: > Rune Strand wrote: > > > > > > I am doing alot of reading, and the problem didnt come with an answer. > > > I dont understand how to get it to continually input numbers and add > > > all those together > > > > Use wh

Re: Time out question

2006-07-03 Thread Rune Strand
Grant Edwards wrote: > I just use signal.alarm(): > > import signal,sys > > def alarmHandler(signum, frame): > raise 'Timeout' > > signal.signal(signal.SIGALRM, alarmHandler) > > while 1: > try: > signal.alarm(5) > t = sys.stdin.readline() > signal.alarm(0) >

Re: ascii character - removing chars from string

2006-07-03 Thread Rune Strand
bruce wrote: > hi... > > i'm running into a problem where i'm seeing non-ascii chars in the parsing > i'm doing. in looking through various docs, i can't find functions to > remove/restrict strings to valid ascii chars. > > i'm assuming python has something like > > valid_str = strip(invalid_str) >

Re: built in zip function speed

2006-07-04 Thread Rune Strand
itertools.izip is usually faster than zip. You can try that. -- http://mail.python.org/mailman/listinfo/python-list

Re: built in zip function speed

2006-07-04 Thread Rune Strand
> so fastest overall you may experience speed-ups by using from itertools import izip and just use izip() instead to avoid the module namespace lookup. The same applies for the list.append() methods. If you're appending some million times a_list = [] a_list_append = a_list.append a_list_append

Re: Module for creating a screenshot of a web page given a URL?

2006-07-05 Thread Rune Strand
[EMAIL PROTECTED] wrote: > Is there a Python module that, given a URL, will grab a screenshot of > the web page it goes to? I'd like to be able to feed such a module a > list of URLs from a file. > > Thanks very much. Not as I know of, but it's easy to write Something like this quasi-code: impor

Re: urllib2 on Windows Vista

2006-07-08 Thread Rune Strand
Sriram Krishnan wrote: > I'm running Python 2.4.3 on Windows Vista June CTP. I'm not able to > open any site using the urllib2 and related family of modules My wil guess is that it is a firewall problem. Perhaps you'll have to specify that python.exe is trusted. -- http://mail.python.org/mailm

Re: Unique Elements in a List

2005-05-09 Thread Rune Strand
You're right. I somehow missed the index part :-o. It's easy to fix though. -- http://mail.python.org/mailman/listinfo/python-list

Re: speeding up Python script

2005-05-17 Thread Rune Strand
Without seeing any code, it's hard to tell, but it's not a wild guess that 'six inside for loops' may be replaced by more efficient ways ;-) -- http://mail.python.org/mailman/listinfo/python-list

Python as client-side browser script language

2005-05-31 Thread Rune Strand
What would it take to create a Firefox extension that enables Python as a script language in the browser - just like Javascript? Is it at all possible? Are the hundred good reasons not to bother? I once made an application that used MozPython[1]. It was fun and very fast compared to the Mod_Python

Strange KeyError using cPickle

2005-06-01 Thread Rune Strand
I'm experiencing strange errors both with pickle and cPickle in the below code: import cPickle as pickle #import pickle from string import ascii_uppercase from string import ascii_lowercase def createData(): d1 = list("Something's rotten") d2 = tuple('in the state of Denmark') d3 =

Re: Strange KeyError using cPickle

2005-06-01 Thread Rune Strand
[Tim Peters] > What is "XWwz"? Assuming it's a bizarre typo for "open", change the > 'w' there to 'wb'. Pickles are binary data, and files holding pickles > must be opened in binary mode, especially since: > > > ... > > (on WinXP, CPython 2.4.1) Thanks Tim. The bizarre 'typo' appears to be cause

Re: how to operate the excel by python?

2005-06-09 Thread Rune Strand
The key is Python for Windows : http://starship.python.net/crew/mhammond/win32/ See here for an Excel dispatch example: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/325735 When doing such operations, I generally save all the Excel files to CSV files and do the operations on them using

Re: how to operate the excel by python?

2005-06-11 Thread Rune Strand
John, I wrote a script that autmates the conversion from XLS to CSV. It's easy. But your points are still good. Thanks for making me aware the xlrd module! -- http://mail.python.org/mailman/listinfo/python-list

Re: windows directory

2005-06-14 Thread Rune Strand
On XP at least you have the environment variable "ProgramFiles". You can fetch the path it holds through os.environ -- http://mail.python.org/mailman/listinfo/python-list

Re: Reading a portion of a file

2007-03-08 Thread Rune Strand
On Mar 8, 5:12 pm, [EMAIL PROTECTED] wrote: > I am using a script with a single file containing all data in multiple > sections. Each section begins with "#VS:CMD:command:START" and ends > with "#VS:CMD:command:STOP". There is a blank line in between each > section. I'm looking for the best way to

Re: How to test if a key in a dictionary exists?

2007-03-10 Thread Rune Strand
Yes, you have name.has_key(name_key) and perhaps better, the in operator: if name_key in name: do something -- http://mail.python.org/mailman/listinfo/python-list

Re: replacing substrings within strings

2007-02-14 Thread Rune Strand
On Feb 14, 1:08 pm, "amadain" <[EMAIL PROTECTED]> wrote: > I was wondering if there was a nicer way to swap the first 2 > characters in a string with the 4th and 5th characters other than: > > darr=list("010203040506") > aarr=darr[:2] > barr=darr[4:6] > darr[:2]=barr > darr[4:6]=aarr > result="".jo

Re: replacing substrings within strings

2007-02-14 Thread Rune Strand
Or, slighly slower, but more general: def swap(s, order=(3,4,2,0,1)): # assert len(s) >= len(order) return ''.join([s[o] for o in order]) + s[6:] -- http://mail.python.org/mailman/listinfo/python-list

Re: rot13 in a more Pythonic style?

2007-02-14 Thread Rune Strand
You could try "some_string".encode('rot_13') -- http://mail.python.org/mailman/listinfo/python-list

Re: Referencing Items in a List of Tuples

2007-02-24 Thread Rune Strand
On Feb 25, 3:01 am, [EMAIL PROTECTED] wrote: > In my case, I have a list of 9 tuples. Each tuple has 30 items. The first > two items are 3-character strings, the remaining 28 itmes are floats. > > I want to create a new list from each tuple. But, I want the selection of > tuples, and their assi

Measure memory usage in Python

2006-04-30 Thread Rune Strand
Is there a way to measure how much memory a data structure use? For instance, what is the footprint of a particular list object like [0,1,2,3,4,5,6,7,8,9]? -- http://mail.python.org/mailman/listinfo/python-list

Re: Measure memory usage in Python

2006-05-01 Thread Rune Strand
gene tani wrote: > Rune Strand wrote: > > Is there a way to measure how much memory a data structure use? For > > instance, what is the footprint of a particular list object like > > [0,1,2,3,4,5,6,7,8,9]? > > i have a note to try this, but haven't got around t

Re: Is Welfare Part of Capitalism?

2006-05-09 Thread Rune Strand
Welfare is not a built-in, but in some distributions it's available as a module. Just type import Welfare. However, be aware of the Welfare.division() queerness. It won't be fixed until the Python 3000 is a fact. There is also some issues with the garbage collection. Under certain circumstances the

Re: John Bokma harassment

2006-05-24 Thread Rune Strand
Xah Lee wrote: > I'm sorry to trouble everyone. But as you might know, due to my > controversial writings and style, recently John Bokma lobbied people to > complaint to my web hosting provider. After exchanging a few emails, my > web hosting provider sent me a 30-day account cancellation notice l

Re: Ping and ARP on both Win and Linux in Python

2008-03-14 Thread Rune Strand
On Mar 13, 9:14 pm, "Mauro \"Baba\" Mascia" <[EMAIL PROTECTED]> wrote: > Hi, this is my question: > > I want to know if several switch (about 50) in a big lan are up and then > know their MAC addresses to do a list that contains host name, ip and mac. > I know only the range of their IP addresses (

Re: How is GUI programming in Python?

2008-04-11 Thread Rune Strand
On Apr 10, 3:54 am, Chris Stewart <[EMAIL PROTECTED]> wrote: ... > > Next, what would you say is the best framework I should look into? > I'm curious to hear opinions on that. GUI-programming in Python is a neanderthal experience. What one may love with console scripts is turned upside-down. Proj

Re: How is GUI programming in Python?

2008-04-11 Thread Rune Strand
On Apr 11, 8:35 pm, Steve Holden <[EMAIL PROTECTED]> wrote: > wxDesigner. Yeah, but it's like Heron of Alexandria's Aeolipile compared to the steam engine of James Watt. IMHO, GUI with Python is pain, pain and utter pain. Even boring and meaningless pain. -- http://mail.python.org/mailman/listin

Re: How is GUI programming in Python?

2008-04-11 Thread Rune Strand
On Apr 12, 12:03 am, Michel Bouwmans <[EMAIL PROTECTED]> wrote: > > Qt Designer. And creating the GUI yourself in the text editor isn't that > bad, plus you have much better control over it. If you like designing isual elements in an editor, that's fine for me! I don't, And as I don't do it all th

Re: MVC in Python for web app dev

2006-03-25 Thread Rune Strand
[EMAIL PROTECTED] wrote: > Please let me state off the cuff that I'm not after a big "Python Vs > Ruby" war or anything here! I'm trying to make the switch to Python for > my web development work as I've been using it for quite some time for > other programming work (albeit mainly hobby and person

Re: Cookbook for beginners?

2006-03-26 Thread Rune Strand
Aahz wrote: > If you were going to name three or five essential recipes from the > Python Cookbook suitable for beginners, what would you pick? > > Yes, this is for _Python for Dummies_, so idioms that aren't in the > Cookbook are also fine. If it's for _beginners_ / _dummies_, I would expect thi

Re: Convert Word .doc to Acrobat .pdf files

2006-03-28 Thread Rune Strand
kbperry wrote: > Questions: > Does Acrobat Pro, have some way to interface with it command-line (I > tried searching, but couldn't find anything)? Is there any other good > way to script word to pdf conversion? > > Note: The word documents do contain images, and lots of stuff besides > just text

Re: Exception handling....dumb question?

2006-03-31 Thread Rune Strand
kbperry wrote: > In Python, > When using the default except (like following) > > try: > some code that might blow up > > except: > print "some error message" > > > Is there a way to show what error it is throwing? > > Like in Java, you can do > catch (Exception e){ > System.out.println

Re: can I get the index number in for x in y loop?

2006-04-03 Thread Rune Strand
JuHui wrote: > >>> a='String' > >>> for x in a: > ... print x > ... > S > t > r > i > n > g > >>> > > can I get the index number of a in the upon loop within for x in a > loop? for x, y in enumerate(a) print x, y -- http://mail.python.org/mailman/listinfo/python-list

Re: Best way to create a copy of a list

2006-04-03 Thread Rune Strand
Frank Millman wrote: > Hi all > > Assume a 2-dimensional list called 'table' - conceptually think of it > as rows and columns. > > Assume I want to create a temporary copy of a row called 'row', > allowing me to modify the contents of 'row' without modifying the > contents of 'table'. > > I used t

Re: How to parse a name out of a web page?

2006-04-05 Thread Rune Strand
Haibao Tang wrote: > with high accuracy... > > My temporary plan is to first recognized consecutive two or three > initial-capitalized words, but certainly we need to do more than that? > Anyone has suggestions? > > Thanks first. It's not easy to say without seeing the HTML. If you the structure

Re: mod_python + apache + winxp => nogo

2006-04-07 Thread Rune Strand
I've set up that combo several times. I haven't had any problems. I just looked at apach.conf, it's the same line. Did you run the mod_python-3.2.8.win32-py2.4.exe installer? -- http://mail.python.org/mailman/listinfo/python-list

Re: how relevant is C today?

2006-04-10 Thread Rune Strand
gregarican wrote: > 1) Smalltalk - The original object oriented programming language. > Influenced anything from Mac/Windows GUI to Java language. No. Simula is the "original object oriented programming language". -- http://mail.python.org/mailman/listinfo/python-list

Re: How to Convert a string into binary

2006-04-15 Thread Rune Strand
HNT20 wrote: > Hello All > def ascii_to_bin(char): ascii = ord(char) bin = [] while (ascii > 0): if (ascii & 1) == 1: bin.append("1") else: bin.append("0") ascii = ascii >> 1 bin.reverse() binary = "".join(bin) zerofix = (8

Re: How to timeout when waiting for raw_input from user ?

2009-12-05 Thread Rune Strand
The easiest wasy is to use the Timer object in the threading module. from threading import Timer -- http://mail.python.org/mailman/listinfo/python-list

Re: How to timeout when waiting for raw_input from user ?

2009-12-05 Thread Rune Strand
On Dec 5, 3:07 pm, Maxim Khitrov wrote: > > Doesn't work on Windows. > > - Max Yes, it does. I've used it a lot, also in Py2Exe apps. Try the documentation example yourself def hello(): print "hello, world" t = Timer(30.0, hello) t.start() # after 30 seconds, "hello, world" will be printed

Re: How to timeout when waiting for raw_input from user ?

2009-12-07 Thread Rune Strand
On Dec 5, 3:42 pm, Maxim Khitrov wrote: > I'm not talking about the Timer, I'm talking about the original > question. There's nothing (that I know of) you can do with a Timer on > Windows to interrupt a raw_input call. That is true. But if the issue here is to present a question, and await answe