[Tutor] User identification and running in the background.
Good morning Users, I've had a quick scan around and can't find a way to identify the user who is logged in on the machine while a script is running? I've seen a few mentions of it being possible using bits of the win32 library but I would have liked my software to be portable with no adjustments. How can I run a script in the background? I will be writing a (prototype) machine control interface and would like the users to be able to log out, but leave the script running. When the next user logs in they can open up a portal (preferably in the system tray) to give them control of the system again. When I link this to the user identification I would be able to vary the access to the machine depending on the access rights of the user. Thank you in advance of any help. Wesley Brooks. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Opening a pdf on a certain page
Hey friendly users, Is there anyway to open a .pdf at a certain page? Been searching the internet, but couldnt find anything. Thanks in advance, Toon Pieton ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] getting all txt files in a folder
Hey friendly users, Is there any way to get all the txt files in a certain folder and all of its "sub"-folders? With sub-folder I mean all the folders inside the previously found folder. Any help would be greatly appreciated Greetings, Toon Pieton ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Opening a pdf on a certain page
[Toon Pieton] | Is there anyway to open a .pdf at a certain page? Been | searching the internet, but couldnt find anything. Pretty certain there isn't. Even if you'd generated the PDF yourself and set an internal anchor there doesn't seem to be a URI which will jump to that point. I'd be really happy to be wrong about that. TJG This e-mail has been scanned for all viruses by Star. The service is powered by MessageLabs. For more information on a proactive anti-virus service working around the clock, around the globe, visit: http://www.star.net.uk ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] getting all txt files in a folder
[Toon Pieton] | Is there any way to get all the txt files in a certain folder | and all of its "sub"-folders? With sub-folder I mean all the | folders inside the previously found folder. Any help would be | greatly appreciated Have a look at os.walk and fnmatch TJG This e-mail has been scanned for all viruses by Star. The service is powered by MessageLabs. For more information on a proactive anti-virus service working around the clock, around the globe, visit: http://www.star.net.uk ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] How to allow user to choose an option from a window
I'm trying to allow a user to select one option from a list. My simple code works: OptionList = ['One', 'Two', 'Three'] while 1: print 'Here are your options:' for option in OptionList: print option optionChosen = raw_input("Which one do you want? ") if optionChosen in OptionList: break print "That is not a valid option. Please re-enter your choice." print "You have chosen: ", optionChosen However, Now I'd like to display the options within a MsgBox-type display and have the user click on the option of choice. Any suggestions of a model I can adapt to accomplish this? Thanks. Urban Landreman ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] getting all txt files in a folder
On 12/12/06, Toon Pieton <[EMAIL PROTECTED]> wrote: > Is there any way to get all the txt files in a certain folder and all of its > "sub"-folders? With sub-folder I mean all the folders inside the previously > found folder. Any help would be greatly appreciated http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/499305 -- Cheers, Simon B [EMAIL PROTECTED] http://www.brunningonline.net/simon/blog/ ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] getting all txt files in a folder
Toon Pieton wrote: > Hey friendly users, > > Is there any way to get all the txt files in a certain folder and all of > its "sub"-folders? With sub-folder I mean all the folders inside the > previously found folder. Any help would be greatly appreciated Using the path module from http://www.jorendorff.com/articles/python/path/index.html it's easy: import path basePath = path.path('path/to/root/folder') for txtPath in basePath.walkfiles('*.txt'): # do something with txtPath e.g. list the names print txtPath Otherwise use os.walk() and fnmatch as Tim suggested. Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Getting the directory the program is in
Hi, I use this: # This is the file name this code is in curfile = "findcurdir.py" #__file__ gives everything so slice off the file name curdir = __file__[:-len(curfile)] print curdir #will print the curdir the file is in #even if this file(module) has been imported I hope it helps Laszlo Antal ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] User identification and running in the background.
| I've had a quick scan around and can't find a way to identify the user | who is logged in on the machine while a script is running? I've seen a | few mentions of it being possible using bits of the win32 library but | I would have liked my software to be portable with no adjustments. | | How can I run a script in the background? I will be writing a | (prototype) machine control interface and would like the users to be | able to log out, but leave the script running. When the next user logs | in they can open up a portal (preferably in the system tray) to give | them control of the system again. When I link this to the user | identification I would be able to vary the access to the machine | depending on the access rights of the user. I very much doubt if even the rest of what you're doing is going to be particularly portable, so I wouldn't worry too much if the logged-on user bit isn't either. It looks to me as though you're working at O/S-specific level. Python doesn't offer any particular abstraction over detached processes etc. In Windows you'd have to use a Service, in *nix a daemon (I think). To talk about possibilities on Windows which I know better, it should be possible to have a service running which can be messaged to by a desktop app run from the system tray or elsewhere. When the desktop app sends its signal to the service it could send through the SID or Token of the logged on user which the service could then use to authorise or not. But this is all quite Win32-specific (as well as being hand-wavingly unspecific). I don't know how you'd go about it on *nix but I bet it's nothing like the same. TJG This e-mail has been scanned for all viruses by Star. The service is powered by MessageLabs. For more information on a proactive anti-virus service working around the clock, around the globe, visit: http://www.star.net.uk ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Opening a pdf on a certain page
[Dave Kuhlman] | On Tue, Dec 12, 2006 at 04:00:29PM -, Tim Golden wrote: | > [Toon Pieton] | > | > | Is there anyway to open a .pdf at a certain page? Been | > | searching the internet, but couldnt find anything. | > | > Pretty certain there isn't. Even if you'd generated the | > PDF yourself and set an internal anchor there doesn't | > seem to be a URI which will jump to that point. I'd | > be really happy to be wrong about that. | > | | I'm assuming that the original poster was asking a Python question, | but just to show that in general this must be possible ... | | I use evince (on Linux) to read PDF docs. When I open a document | the second time, evince automatically shows the last page I was | viewing when I previously closed evince. And, the following | command: | | $ evince -p 12 somedocument.pdf | | will open that document to page 12. Well I was certainly very narrow in my thinking, assuming that everyone was running Acrobat Reader and/or Firefox like myself. Clearly you're right that since PDFs *have* pages, any reader may offer a facility to jump to one. Thanks for the education! TJG This e-mail has been scanned for all viruses by Star. The service is powered by MessageLabs. For more information on a proactive anti-virus service working around the clock, around the globe, visit: http://www.star.net.uk ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] How to allow user to choose an option from a window
If you mean which type of GUI model to use you have at least two popular choices. Tkinter: It's bundled with Python, and there's a tutorial at: http://www.pythonware.com/library/tkinter/introduction/ wxPython: My GUI of choice. http://wxpython.org A quick and dirty example in wxPython of what you wanted: import wx class MainWindow(wx.Frame): def __init__(self,parent,id,title): wx.Frame.__init__(self,parent,wx.ID_ANY,title,size=(200,200)) self.radiobox = wx.RadioBox(self,wx.ID_ANY ,'Options',choices=['One','Two','Three'],style=wx.RA_SPECIFY_ROWS) self.Bind(wx.EVT_RADIOBOX,self.OnRadioBoxChoose,self.radiobox) self.Show() def OnRadioBoxChoose(self,event): choice = self.radiobox.GetStringSelection() wx.MessageBox("You selected: %s" % choice) app = wx.PySimpleApp() frame = MainWindow(None,-1,"Options") app.MainLoop() On 12/12/06, [EMAIL PROTECTED] < [EMAIL PROTECTED]> wrote: I'm trying to allow a user to select one option from a list. My simple code works: OptionList = ['One', 'Two', 'Three'] while 1: print 'Here are your options:' for option in OptionList: print option optionChosen = raw_input("Which one do you want? ") if optionChosen in OptionList: break print "That is not a valid option. Please re-enter your choice." print "You have chosen: ", optionChosen However, Now I'd like to display the options within a MsgBox-type display and have the user click on the option of choice. Any suggestions of a model I can adapt to accomplish this? Thanks. Urban Landreman ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Opening a pdf on a certain page
On Tue, Dec 12, 2006 at 04:00:29PM -, Tim Golden wrote: > [Toon Pieton] > > | Is there anyway to open a .pdf at a certain page? Been > | searching the internet, but couldnt find anything. > > Pretty certain there isn't. Even if you'd generated the > PDF yourself and set an internal anchor there doesn't > seem to be a URI which will jump to that point. I'd > be really happy to be wrong about that. > I'm assuming that the original poster was asking a Python question, but just to show that in general this must be possible ... I use evince (on Linux) to read PDF docs. When I open a document the second time, evince automatically shows the last page I was viewing when I previously closed evince. And, the following command: $ evince -p 12 somedocument.pdf will open that document to page 12. Dave -- Dave Kuhlman http://www.rexx.com/~dkuhlman ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Accessing the name of a Function
Greetings: Is it possible, from inside a stand-alone function (not a member of a class), to access the string representation of the function's name? If so, how? Regards, Barry [EMAIL PROTECTED] 541-302-1107 We who cut mere stones must always be envisioning cathedrals. -Quarry worker's creed ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Accessing the name of a Function
* Carroll, Barry <[EMAIL PROTECTED]> [061212 23:54]: >Greetings: > > > >Is it possible, from inside a stand-alone function (not a member of a >class), to access the string representation of the function's name? If >so, how? Probably, but it's dirty like help (sys._getframe would be your ticket into this), but you ask on the tutor mailing list, so you'll probably don't want this: def func(x): return 2 * x gunc = func del func print gunc(10) The best you can hope to derive is "func" here, but as you can see, functions are only objects that can be assigned freely. (Spoiler: it's sys._getframe(0).f_code.co_name, but it will always only know the name the function was defined under. No way to know how it was named when it was called. So it's not worth much.) Andreas > > > >Regards, > > > >Barry > >[EMAIL PROTECTED] > >541-302-1107 > > > >We who cut mere stones must always be envisioning cathedrals. > >--Quarry worker's creed > > > > References > >Visible links >1. mailto:[EMAIL PROTECTED] > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Getting the directory the program is in
* Laszlo Antal <[EMAIL PROTECTED]> [061212 18:12]: > Hi, > > I use this: > > # This is the file name this code is in > curfile = "findcurdir.py" > #__file__ gives everything so slice off the file name > curdir = __file__[:-len(curfile)] > print curdir > #will print the curdir the file is in > #even if this file(module) has been imported What about using os.path.dirname and os.path.basename for this splitting? Andreas ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Accessing the name of a Function
Andreas: You're right, that is kind of messy and somewhat limited. In the present case, however, it is the function's defined name that I want, so this would work okay. I'm guessing that there is a way to determine the number and names of the arguments to the function as well. I'll go look at the sys module and see what I can find. Regards, Barry [EMAIL PROTECTED] 541-302-1107 We who cut mere stones must always be envisioning cathedrals. -Quarry worker's creed > -Original Message- > From: Andreas Kostyrka [mailto:[EMAIL PROTECTED] > Sent: Tuesday, December 12, 2006 4:05 PM > To: Carroll, Barry > Cc: tutor@python.org > Subject: Re: [Tutor] Accessing the name of a Function > > * Carroll, Barry <[EMAIL PROTECTED]> [061212 23:54]: > >Greetings: > > > > > > > >Is it possible, from inside a stand-alone function (not a member of a > >class), to access the string representation of the function's name? > If > >so, how? > Probably, but it's dirty like help (sys._getframe would be your ticket > into this), but you ask on the tutor mailing list, so you'll probably > don't want this: > > def func(x): > return 2 * x > > gunc = func > del func > > print gunc(10) > > The best you can hope to derive is "func" here, but as you can see, > functions are only objects that can be assigned freely. > > (Spoiler: it's sys._getframe(0).f_code.co_name, but it will always > only know the name the function was defined under. No way to know how > it was named when it was called. So it's not worth much.) > > Andreas > > > > > > > >Regards, > > > > > > > >Barry > > > >[EMAIL PROTECTED] > > > >541-302-1107 > > > > > > > >We who cut mere stones must always be envisioning cathedrals. > > > >--Quarry worker's creed > > > > > > > > References > > > >Visible links > >1. mailto:[EMAIL PROTECTED] > > > ___ > > Tutor maillist - Tutor@python.org > > http://mail.python.org/mailman/listinfo/tutor > ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Organizing 15500 records, how?
I'm writing a program to analyse the profiles of the 15500 users of my forum. I have the profiles as html files stored locally and I'm using ClientForm to extract the various details from the html form in each file. My goal is to identify lurking spammers but also to learn how to better spot spammers by calculating statistical correlations in the data against known spammers. I need advise with how to organise my data. There are 50 fields in each profile, some fields will be much more use than others so I though about creating say 10 files to start off with that contained dictionaries of userid to field value. That way I'm dealing with 10 to 50 files instead of 15500. Also, I am inexperienced with using classes but eager to learn and wonder if they would be any help in this case. Any advise much appreciated and thanks in advance, Thomas ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Confusing Unicode Conversion Problem.
I've got a script that uses com to read columns from an excel workbook(very slow for 6500ish items :/ ) and I'm getting this error: 'ascii' codec can't encode character u'\xa0' in position 11: ordinal not in range(128) Error with: FRAMEMRISER of type: Excel Row : 6355 FRAMEMRISER is exactly how the item looks in excel. What I don't get is why it prints to my screen fine, but I can't get the darn thing to convert to a string. I think xa0 is a space (like ' '), which location 11 puts it at the end of the of the word, basically invisible. I've successfully used my script to import several columns, but this one is being a pain. My code in question: try: while xlSht.Cells(row,col).Value != None: tempValue = xlSht.Cells(row,col).Value tempString = str(tempValue).split('.')[0] ExcelValues.append(tempString) Row = 1 + row # Increment Rows. except UnicodeEncodeError, msg: # Exit the system if error. print msg print "Error with: " + tempValue + " of type: " + str(type(tempValue)) print "Excel Row : " + str(row) Thanks in advance. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor