Re: A useful, but painful, one-liner to edit money amounts
On Aug 5, 7:06 pm, Chris Withers ch...@simplistix.co.uk wrote: Peter Otten wrote: locale.setlocale(locale.LC_ALL, (en_US, UTF-8)) 'en_US.UTF8' print locale.currency(13535, grouping=True) $13,535.00 Okay, so if I'm writing a wsgi app, and I want to format depending on the choices of the currently logged in users, what would you recommend? I can't do setlocale, since that would affect all users, and in a mult-threaded environment that would be bad. Does that mean the whole locale package is useless to all web-app builders? Chris from re import * class editmoney(float): def __init__(self,mymoney): self.mymoney = mymoney def __str__(self): temp = %.2f % self.mymoney profile = compile(r(\d)(\d\d\d[.,])) while 1: temp, count = subn(profile,r\1,\2,temp) if not count: break return temp -- http://mail.python.org/mailman/listinfo/python-list
Re: KinterBasDB - how to change the mode: embedded/server
On Jun 11, 5:07 pm, durumdara durumd...@gmail.com wrote: Hi! I want to use KinterBasDB in mixed mode: sometimes embedded, sometimes real local/remote server. How can I set up the connection to KinterBasDB can determine, what mode I want to use? Thanks for your help: dd you could use 2 connection strings and make the selection yourself as needed. e.g. def kbconnector(connectionmode): if connectionmode=='use_embedded': myonnectionstring=. elif connectionmode=='use_real': myconnectionstring=kinterbasdb.connect return myconnectionstring #connect to the embedded server somemode='use_embedded' myconnector=kbconnector(somemode) mycursor=myconnector.cursor() -- http://mail.python.org/mailman/listinfo/python-list
Re: Cross-platform way to retrieve the current (Operative system) DNS server IP address in python
On Apr 22, 4:55 pm, joamag joa...@gmail.com wrote: Does anybody know a cross platform way to retrieve the default DNS server IP address in python ? Thanks ! João import os,urllib2,re def getIpAddr(): Function for parsing external ip adress by pinging dyndns.com External_IP=urllib2.urlopen('http://checkip.dyndns.com/').read() m = re.search(r(([0-9]+\.){3}[0-9]+), External_IP) my_IP= m.group(1) return my_IP print('Current Ip from DynDns : %s ') % getIpAddr() this gets you your ip address hope it helps. -- http://mail.python.org/mailman/listinfo/python-list
Re: PyQt processEvents not processing
On Nov 8, 12:04 am, David Boddie da...@boddie.org.uk wrote: On Saturday 07 November 2009 05:12, DarkBlue wrote: qt 4.5.3 pyqt 4.6.1 python 2.6 I have this QtTable widget which I want to refresh once about every 2 seconds with new data. so I do : def updateSchedule(self): for j in range(0,10): doUpdate() QtCore.processEvents() sleep(2) unfortunately QT appears to wait until the for loop finishes and only then paints the QtTable widget on the screen showing only the latest updated result. It's difficult to know exactly why this is without more context. Calling the application's processEvents() method should give the user interface the chance to update itself, but perhaps you need to explicitly call update() on the QTableView or QTableWidget instance to ensure that it is refreshed. An alternative way to do this is to use a timer to update the table every two seconds. David As per your suggestion I added a timer to the init part and now the update works as expected , even without calls to processEvents. self.myTimer = QtCore.QTimer(self) QtCore.QObject.connect(self.myTimer,QtCore.SIGNAL(timeout()), self.doUpdate) self.timerTime = 0 self.myTimer.start(2000) Thanks Db -- http://mail.python.org/mailman/listinfo/python-list
Execution order
Here is some code from a pyqt4.5.4 application on python 2.6 def findData(self): self.ui.label.setText('Processing... ') # here we do something which takes a few seconds self.refreshGrid() The problem is that the text in the self.ui.label is only changed on screen after the self.refreshGrid() has finished executing rather than before. How do I achieve the expected result ? Thanks Db -- http://mail.python.org/mailman/listinfo/python-list
Re: Execution order
On Sep 11, 9:34 pm, Diez B. Roggisch de...@nospam.web.de wrote: DarkBlue wrote: Here is some code from a pyqt4.5.4 application on python 2.6 def findData(self): self.ui.label.setText('Processing... ') # here we do something which takes a few seconds self.refreshGrid() The problem is that the text in the self.ui.label is only changed on screen after the self.refreshGrid() has finished executing rather than before. How do I achieve the expected result ? You can make Qt process all pending events once, via QCoreApplication.processEvents. This should trigger the redraw. Diez Thanks ! That helped. :) -- http://mail.python.org/mailman/listinfo/python-list
print() a list
I am trying to get used to the new print() syntax prior to installing python 3.1: test=[[VG, Virgin Islands, British],[VI, Virgin Islands, U.S.], [WF, Wallis and Futuna],[EH, Western Sahara],[YE, Yemen], [ZM, Zambia],[ZW, Zimbabwe],] #old print for z in test: if z[0].startswith('W'): print z[0] , z[1] print # new print() # now a list would have to be printed like this to be equal to old print ? for z in test: if z[0].startswith('W'): print('%s %s') % (z[0] , z[1]) print # this output prints the brackets etc. too, not what we want for z in test: if z[0].startswith('W'): print(z[0] , z[1]) print on python 2.6 I get following output: WF Wallis and Futuna WF Wallis and Futuna ('WF', 'Wallis and Futuna') Before actually installing python 3.1 my question is if the py2to3 converter also considers this situation ? Thanks Db -- http://mail.python.org/mailman/listinfo/python-list
pyuno store OO object into blob
Hello Python 2.5.1 Qt 4.4.0 PyQt 4.4.2 OO 2.4.1 Firebird 2.1 I want to store an openoffice writer object into a blob field using the pyuno bridge. I read about the possibility of using streams , but only see some old basic or java examples . The writer document has been created and stored into an odf file on disk. How to get it from there into the blob ? Thanks for any ideas. -- http://mail.python.org/mailman/listinfo/python-list
Re: sqlobject issue/question...
On Dec 29, 12:27 pm, bruce [EMAIL PROTECTED] wrote: hi i'm playing around, researching sqlobject, and i notice that it appears to require the use of id in each tbl it handles in the database. if i already have a db schema, and it doesn't use 'id' as an auto-generated field, does that mean that i can't use/implement sqlobject. is there a way to overide this function/behavior... thanks If you want to use all the power in sqlobject you will need the id , you may get away without having one if you use the build in raw sql facility exclusively , but then again you probably would not need sqlobject anyway. You also might want to take a look at sqlalchemy . Whichever you choose, if you are used to write complex queries in sql it will take some time to wrap your mind around any of them. Db -- http://mail.python.org/mailman/listinfo/python-list
Re: kniterbasdb and datetime
On Dec 13, 7:45 pm, Laszlo Nagy [EMAIL PROTECTED] wrote: Hi All, I connected to a FireBird 1.5 database this way: import kinterbasdb kinterbasdb.init(type_conv=200) # Seehttp://kinterbasdb.sourceforge.net/dist_docs/usage.html#faq_fep_is_mx... Then I try to update the database: sql = UPDATE TABLE1 SET DATEFIELD=? where ID = ? params=[datetime.date(2007,11,01),2341] cursor.execute(sql,params) I get this error: kinterbasdb.ProgrammingError: (-413, 'isc_dsql_execute: \n conversion error from string 2007-11-01') What is wrong here? Thanks, Laszlo Kinterbasdb probably expects the format looking like month/day/year rather than year-month-day I have an old pythoncard app where there was the same issue when picking a date using the wx.calendar widget, Rearranging the format solved the problem. here is the relevant code snippet ,maybe it gives you the idea: def on_doCalDate_command(self,event): # this the way to get a wx.calendar date into a # format suitable for kinterbasdb D=[] MYDATE=str(self.components.Calendar1.date) SPLITDATE=MYDATE.split('-') for data in SPLITDATE: D.append(data) YR=D[0] MO=D[1] DY=D[2] JOBDATE=MO+/+DY+/+YR DB -- http://mail.python.org/mailman/listinfo/python-list
Kinterbasdb needs new maintainer
Sorry to interrupt the regular programming here . As has been reported on some websites the maintainer of kinterbasdb David Rushby has died last month after a diving accident. Kinterbasdb is the python wrapper around the Firebird database api and an excellent opensource project. The hope is , that this message will reach someone in the opensource developer community , who is willing to step up and continue the great work done by David . Thank you http://www.firebirdnews.org/?p=1252 http://kinterbasdb.sourceforge.net/ -- http://mail.python.org/mailman/listinfo/python-list
Document creation with odfpy
Hello I hope here is the right place to ask this: I use the python odfpy library to create and load an odt file , however, spaces in the passed in text are removed. http://opendocumentfellowship.org/development/projects/odfpy python2.4 from odf.opendocument import OpenDocumentText from odf.style import Style, TextProperties from odf.text import H, P, Span def SaveIt(MYTEXT) : doc = OpenDocumentText() for line in MYTEXT: p = P(text=line) doc.text.addElement(p) doc.save('mynewfile.odt') MYTEXT is a list containing lines from a wx.TextCtrl if a line is: abcabc abcabc abcabc the result in the odt file looks like: abcabc abcabc abcabc Is there anything I am doing wrong ? Thanks Db -- http://mail.python.org/mailman/listinfo/python-list
wx.grid 2.6.1.0 events
Hello pythoncard wx 2.6.1 python 2.4.x kinterbasdb firebird I have a wx.grid filled with data from a database one of the fields is a blob field with text data, which I want to display in some adjacent text control when I scroll through the grid. The question is which wx.EVT_XXX do I need to use and how to 'connect ' the wx.grid to my TextArea control ,so that the correct data gets displayed after any row change? Thanks for any hints. Db -- http://mail.python.org/mailman/listinfo/python-list
Re: Mastering Python
Before we get to far away from the original question... as you have may have noticed you reached one of the best user groups on the net , where help from the top gurus and best minds in the python universe is only a question away. Go for it, you are in good hands. Db -- http://mail.python.org/mailman/listinfo/python-list
Re: How can I speed this function up?
Just to show how much a system set up impacts these results: Result from suse10.1 64 , python 2.4 with AMD FX-55 cpu and about 12 active apps running in the background. 7200rpm sata drives. Preparing data... [write_data1] Preparing output file... [write_data1] Writing... [write_data1] Done in 5.43 seconds. [write_data4] Preparing output file... [write_data4] Writing... [write_data4] Done in 4.41 seconds. [write_data_flush] Preparing output file... [write_data_flush] Writing... [write_data_flush] Done in 5.41 seconds. [write_data_per_line] Preparing output file... [write_data_per_line] Writing... [write_data_per_line] Done in 4.4 seconds. [write_data_once] Preparing output file... [write_data_once] Writing... [write_data_once] Done in 4.28 seconds. -- http://mail.python.org/mailman/listinfo/python-list
Kde Taskbar
Hello In linux I use kmail as my email client under KDE, if a message comes in the Kontact button in the taskbar changes to blue. How can I have the same behaviour in a python app ? I have a python script which runs nicely under linux now every so often I want to be notified by some event, in this case that a record has been added to a database and I want to have the application button in the taskbar to change color Thanks for any pointers , I am out of my depth here Db -- http://mail.python.org/mailman/listinfo/python-list
Re: Kde Taskbar
Diez B. Roggisch wrote: pykde afaik supports systray-iconified apps. And you could use the dcop-mechanisms that are available as command line tools as well I guess, and invoke knotify. Hope this gives you some pointers - I'm currently on my mac so I can't provide an actual example. Diez Thank you , a quick look at pykde tells me that this will need some research Db -- http://mail.python.org/mailman/listinfo/python-list
Re: Kde Taskbar
David Boddie wrote: On Saturday 07 October 2006 14:59, DarkBlue wrote: In linux I use kmail as my email client under KDE, if a message comes in the Kontact button in the taskbar changes to blue. How can I have the same behaviour in a python app ? You need to activate the window associated with the application. I have a python script which runs nicely under linux now every so often I want to be notified by some event, in this case that a record has been added to a database and I want to have the application button in the taskbar to change color If the script is running in a console, you'll need to activate the window containing the console. I tried doing this by accessing konsole's DCOP interface, but couldn't find a suitable method to call. If you know which konsole your script is running in, you might find that you can raise the window with dcop konsole-pid konsole-mainwindow#1 raise where pid is the process ID of the konsole. This might have the effect of causing its taskbar button to change color. You can find information about the konsole from the KONSOLE_* environment variables. It would be good if konsole had a DCOP method that enabled you to activate its window, or if kicker exported an interface for the taskbar, or even if kwin had some way of letting you activate a window given its ID. Unfortunately, I couldn't find methods for any of these, so you would have to think about using PyKDE to get at this functionality. It would be good if someone could prove me wrong on any of this. ;-) David My python app actually is a pythoncard app which I hope will make things easier. Db -- http://mail.python.org/mailman/listinfo/python-list
baffling sql string
Following is a code snippet from a pythoncard app the problem is with the sql string called iq1 If either mysubject or mytalktext contains an apostrophe the update fails : Example: mysubject=Let's Eat this fails mysubject=Lets Eat this works fine What options do I have to avoid this issue but still can use apostrophes in my input data ? mysubject=self.components.TextField1.text mytalktext=self.components.TextArea1.text mymsgno=self.myamsgno iq1=update MSGTALK set msgdate='NOW',subject='%s',talktext='%s' where msgno= %d % (mysubject,mytalktext,mymsgno) try: self.cur.execute(iq1) con1.commit() self.components.TextArea2.appendText('Update ok\n') except: self.components.TextArea2.appendText('Problem during update command\n') self.components.TextArea2.appendText(iq1) (hope the intendation did not get too messed up ) Thanks -- http://mail.python.org/mailman/listinfo/python-list
Re: baffling sql string
Duncan Booth wrote: ... depending on your actual database you might need to use something other than %s to specify the parameters. Check out 'paramstyle' for your database connection. Thank you all for prompt suggestions I am using firebird 1.5.3 with kinterbasdb Db -- http://mail.python.org/mailman/listinfo/python-list
mac address
Hello Is it possible to get the mac address of a device with python 2.4 using code which works in wxp and linux rather than requiring some code for windows and some other code for linux ? Db -- http://mail.python.org/mailman/listinfo/python-list
Netstat Speed
Following code works . My question is can I make it faster ? def activeip(checkip): # if there is any line returned we set activeb to 1 indicating that # this ip is active during a netstat run activeb=0 for line in os.popen(netstat -a -n | grep '%s' % checkip) : s=line if s '' : activeb=1 return activeb Thanks -- http://mail.python.org/mailman/listinfo/python-list
Re: Netstat Speed
s=line is actually indented even if it does not appear to be so :) Db -- http://mail.python.org/mailman/listinfo/python-list
Re: Netstat Speed
Sybren Stuvel wrote: DarkBlue enlightened us with: Following code works . No it doesn't - it's indented badly. I guess you mean something like: def activeip(checkip): # if there is any line returned we set activeb to 1 indicating that # this ip is active during a netstat run activeb=0 for line in os.popen(netstat -a -n | grep '%s' % checkip) : s=line if s '' : activeb=1 return activeb Also try to use != instead of . Being equal or not has nothing to do with being larger or smaller. My question is can I make it faster ? As soon as you set activeb=1, it no longer changes to any other value. That means that you could immediately return from that point. It's also cleaner to actually close an open file: def activeip(checkip): # if there is any line returned we set activeb to 1 indicating that # this ip is active during a netstat run activeb = 0 netstat = os.popen(netstat -a -n | grep '%s' % checkip) for line in netstat: s = line if s: activeb = 1 break netstat.close() return activeb Another way would be to let grep do the work for you. Pass it the '-q' option and check its exit code. Sybren Thank you for pointing that out. Speed did not improve , but it definitely is cleaner code now. Have a nice day Db -- http://mail.python.org/mailman/listinfo/python-list
PythonCard question
Is it possible to create pythoncard textField components dynamically during run time ? Something on the lines of pseudo code : def make_textfield(length,topleftposx,topleftposy): doit self.make_textfield(120,20,20) Thanks for any ideas. -- http://mail.python.org/mailman/listinfo/python-list
Re: Time out question
Sure, see function setdefaulttimeout in module socket. Just call it as you wish before trying the DB connection and catch the resulting exception. Alex That should do it. Thanks Db -- http://mail.python.org/mailman/listinfo/python-list
Time out question
My application makes several connections to a remote database server via tcp/ip. Usually all is fine,but occasionally the server is down or the internet does not work and then there is the 30 sec to several minutes timeout wait for the tcp to give up. Is there anything I can do without using threads,sockets,twisted etc. to have following : pseudocode : try for 10 seconds if database.connected : do your remote thing except raise after 10 seconds abort any connection attempt do something else Thanks -- http://mail.python.org/mailman/listinfo/python-list
Re: wxPython GUI designer
Take a look at pythoncard , we use it to produce database frontends , but apparently it also can be used for simple graphics apps and others. However if you are used to things like the Delphi IDE to build a gui app , then prepare to shed lots of tears before overcoming the initial disbelieve, that there is nothing better available for python. -- http://mail.python.org/mailman/listinfo/python-list
wxPython install question
Trying to install wxPython on Suse10.1 64 with gcc4.1.0 and get wxPython-src-2.6.3.2/wxPython # python setup.py install Found wx-config: /usr/local/bin/wx-config Using flags: --toolkit=gtk2 --unicode=no --version=2.6 Preparing CORE... Preparing GLCANVAS... Preparing STC... Preparing GIZMOS... Preparing ANIMATE... running install running build running build_py copying wx/__version__.py - build-gtk2/lib.linux-x86_64-2.4/wx copying wx/build/build_options.py - build-gtk2/lib.linux-x86_64-2.4/wx/build running build_ext building '_glcanvas' extension gcc -pthread -fno-strict-aliasing -DNDEBUG -O2 -fmessage-length=0 -Wall -D_FORTIFY_SOURCE=2 -g -fPIC -DSWIG_TYPE_TABLE=_wxPython_table -DHAVE_CONFIG_H -DWXP_USE_THREAD=1 -UNDEBUG -DGTK_NO_CHECK_CASTS -D__WXGTK__ -D_FILE_OFFSET_BITS=64 -D_LARGE_FILES -DNO_GCC_PRAGMA -Iinclude -Isrc -I/usr/local/lib/wx/include/gtk2-ansi-release-2.6 -I/usr/local/include/wx-2.6 -I/usr/include/cairo -I/usr/include/freetype2 -I/usr/X11R6/include -I/usr/include/libpng12 -I/opt/gnome/include/gtk-2.0 -I/opt/gnome/lib64/gtk-2.0/include -I/opt/gnome/include/atk-1.0 -I/opt/gnome/include/pango-1.0 -I/opt/gnome/include/glib-2.0 -I/opt/gnome/lib64/glib-2.0/include -I/usr/include/python2.4 -c contrib/glcanvas/gtk/glcanvas_wrap.cpp -o build-gtk2/temp.linux-x86_64-2.4/contrib/glcanvas/gtk/glcanvas_wrap.o -O3 contrib/glcanvas/gtk/glcanvas_wrap.cpp: In function ‘PyObject* _wrap_new_GLContext(PyObject*, PyObject*, PyObject*)’: contrib/glcanvas/gtk/glcanvas_wrap.cpp:1737: error: ‘wxGLCanvas’ was not declared in this scope contrib/glcanvas/gtk/glcanvas_wrap.cpp:1737: error: ‘arg2’ was not declared in this scope contrib/glcanvas/gtk/glcanvas_wrap.cpp:1737: error: expected primary-expression before ‘)’ token contrib/glcanvas/gtk/glcanvas_wrap.cpp:1737: error: expected `;' before numeric constant contrib/glcanvas/gtk/glcanvas_wrap.cpp:1740: error: ‘wxGLContext’ was not declared in this scope contrib/glcanvas/gtk/glcanvas_wrap.cpp:1740: error: ‘arg4’ was not declared in this scope then it errors out . What is wrong ? The wxwidgets compiled without a hitch. Thanks -- http://mail.python.org/mailman/listinfo/python-list
Import elfclass32 issue
Hello Suse10.1 64 new install if I try to import anything into python2.4.2 like : python - c import kinterbasdb I get this : wrong ELF class: ELFCLASS32 Before doing anything wrong , what would be the right thing to do to get rid of this error ? Thanks. -- http://mail.python.org/mailman/listinfo/python-list
Re: Import elfclass32 issue
Sybren Stuvel wrote: file /path/to I installed the package on other 64 machines running suse9.2 64 and 9.3 64 without trouble That's the way : python setup.py build result: successfull python setup.py install result: successfull then tried to import and I get the elfclass32 error and that's all I did. The suse10.1 installation is pristine only auto updated with the latest patches of the day. Db -- http://mail.python.org/mailman/listinfo/python-list
Re: Import elfclass32 issue
Fredrik Lundh wrote: if you do, it's a SuSE problem (this wouldn't be the first time SuSE ships broken Python software) Thanks for the input . Following your message I reinstalled python2.4 and the modules I want to use and now everything is fine. -- http://mail.python.org/mailman/listinfo/python-list
Pythoncard question
I am trying to port a Delphi database application to python on linux with a firebird database backend and I am using pythoncard to recreate the gui. I will have about 25 delphi forms to be recreated and I would like to know what is the best way to call them up from within each other . There is a main screen where I must be able to call up any of the subscreens and on any given subscreen there would be buttons to call up 1-5 of the other subscreens or go back to the mainscreen. The database is connected on the mainscreen and relevant connections/cursors shall be accessible from any of the subscreens. While I am able to connect to the database and create the different screens I am stumped at how to efficiently call them up and pass the cursors between them as needed. Sorry for the long post. Thanks for any hint Db -- http://mail.python.org/mailman/listinfo/python-list
Re: Unpacking of query result
Hello Following part of an database query works fine : self.cur=con1.cursor self.cur.execute('select a,b,c,d from t1') for (a,b,c,d) in self.cur: print a,b,c,d but how to do this: self.cur.execute(sql_select_text_put_in_at_runtime) for (whatever_was_in_the_select_text_part_of_the_query) in self.cur: print 'returned result set' Will it be necessary to parse the sql string and find any possible return columns or is there a better way so that the query can be used generically , that is without knowing at coding time what or how many columns will be returned ? Thanks Db -- http://mail.python.org/mailman/listinfo/python-list
Re: Unpacking of query result
Thank you Mission accomplished. Have a nice sunday Db -- http://mail.python.org/mailman/listinfo/python-list
Re: finding IP address of computer
Chris wrote: How do I find and print to screen the IP address of the computer my python program is working on? def readip(): import re, urllib f = urllib.urlopen('http://checkip.dyndns.org') s = f.read() m = re.search('([\d]*\.[\d]*\.[\d]*\.[\d]*)', s) return m.group(0) myip = readip() -- http://mail.python.org/mailman/listinfo/python-list
Re: ssh question
should read ssh , (probably should not post anything so late in the evening) Db -- http://mail.python.org/mailman/listinfo/python-list
ssl question
Hello python 2.4 I want connect to another linux machine via ssl , after password entry execute : cat /home/myfile.txt and return the result into a list for further processing then close the connection What is the safest and best way to do this ? Db -- http://mail.python.org/mailman/listinfo/python-list
Line replace
Hello I need some help I have a text file which changes dynamically and has 200-1800 lines. I need to replace a line , this line can be located via a text marker like : somelines # THIS IS MY MARKER This is the line to be replaced somemorelines My question is how to do this in place without a temporary file , so that the line after the marker is being replaced with mynewlinetext. Thanks Nx -- http://mail.python.org/mailman/listinfo/python-list
Re: Line replace
Steven D'Aprano wrote: Let me see if I understand your problem... you need to edit a text file in place at the same time that another process is also changing the file in place? That's hard. You need some way to decide who gets precedence if both you and the other process both try to change the same line simultaneously. I think the only way this is even half-doable will be if: - the other process writing to the file only appends to the end of the file, and does not try to write to the middle; - the new line you are writing is the same length as the old line you are replacing; - and you are running an operating system that allows two processes to have simultaneous write access to a file. What problem are you trying to solve by having simultaneous writes to the same file? Perhaps there is another way. Thanks for your reply. I would have no problem to let other processes finish their writing duty to the file and my script only gets access when no other process is working with the file. The file written to is the hosts.allow file which is changed often by the blockhosts.py script when some ssh access is attempted. Now blockhosts.py works great , but sometimes our mobile clients try to access from ip addresses which are completely blocked to avoid the thousands of scripted attacks showing up in our logs. Now our authorized clients register themselves automatically with computername,id and ip address via a small python script which sends this information to a firebird database on our server. A serverside script scans the database ever so often and changes the hosts.allow file to enable authorized clients to log on via ssh if they have moved out of their original areas ( like traveling from china to india and logging in from a hotel room) Most of the clients run Suse9.3 so does the server some are wxp machines which get their ssh access via winscp or putty if needed. Every client has a marker in the hosts.allow file so if a change occurs one line shall be replaced by another line on the fly. I hope this describes it. Nx -- http://mail.python.org/mailman/listinfo/python-list
Re: Line replace
Why don't you use the database to store those markers? It should support concurrent updates properly. That's a database's job. The markers are just there to have a static way to find the line after the marker, which is the one which might have to be changed. Nx -- http://mail.python.org/mailman/listinfo/python-list
Re: Line replace
OK, why don't you store those changing lines in the database? Can you arrange for those changeable lines to be fixed length, i.e. by padding with spaces or something? If you can, then you could just overwrite them in place. Use flock or fcntl (Un*x) or the comparable Windows locking primitives to make sure other processes don't update the file simultaneously. hmm , the line is actually being read from a database and now needs to be written into a file replacing the line after the marker... the line contains only an ip address pseudocode is like this: get newlinetext from database # this is ok done with kinterbas preferably check if file not in use by other process open file and find desired marker go to line after marker and replace that one with newlinetext close the file Should be easy, but I am suffering from New Year writer's block.. Nx -- http://mail.python.org/mailman/listinfo/python-list
Re: Line replace
Thank you for all the suggestions It appears the safest solution still is using a temp file as was so apt suggested further up here without it I maybe white water rafting without a canoe. I also will test the feasibility to regenerate the whole file from the database. Nx -- http://mail.python.org/mailman/listinfo/python-list
Automate webpage refresh
I am trying to write a script (python2.3) which will be used with linux konqueror to retrive 2 webpages alternatively every 2 minutes. My question is how can I send alternative args (the url) to the same invocation of konqueror which I started with def pipedreams(program, *args): pid = os.fork() if not pid: os.execvp(program, (program,) + args) return os.wait()[0] pipedreams(konqueror,url1) Obviously every time I call pipedreams I would open a new instance which is exactly what I do not want. My pseudocode : if timecounter == 60 : send url1 to konqueror to fetch display elif timecounter == 120: send url2 to konqueror to fetch % display timecounter = 0 Thanks for any hints D.B. -- http://mail.python.org/mailman/listinfo/python-list
Re: Automate webpage refresh
Thanks for replies . dcop , hmmm I had not thought of this . D.B. -- http://mail.python.org/mailman/listinfo/python-list