mod_python
I can't figure out how to build this type of program using the publisher handler. I have the following connected to the program SetHandler python-program PythonHandler mod_python.publisher PythonDebug On But what I would like to do would be have a german word as the parameter in the HTTP request and have the english world printed out on the screen. Yes this will be a small dictionary but I just want to be able to understand how to build the program and have it work without any errors. Thanks for any help. PS I understand the example of printing the say portion in the mod_python manual but can't get past that. Again Thanks!! -- http://mail.python.org/mailman/listinfo/python-list
Re: mod_python
I have created the following database but the following errors occur
when trying to execute the code.
html source:
Click here to display information from Chocolate menu:
Press to view the display
Please provide data for chocolate to be added:
Name:
Rating:
Price :
form.py source
import MySQLdb
def addchocolate(z_Name, z_rating, z_price):
# make sure the user provided all the parameters
if not (z_Name and z_rating and z_price):
return "A required parameter is missing, \
please go back and correct the error"
db =
MySQLdb.connect(host="localhost",user="hayward",passwd="hayward",db="hayward")
cursor = db.cursor()
cursor.execute(
"""INSERT INTO InventoryList (artist, title, rating) VALUES (%s,
%s, %s)""", (z_Name, z_rating, z_price) )
db.commit()
cursor.close()
db.close()
def display(rating):
db =
MySQLdb.connect(host="localhost",user="hayward",passwd="hayward",db="hayward")
cursor = db.cursor()
cursor.execute("""SELECT * FROM InventoryList""")
result = cursor.fetchall()
cursor.close()
db.close()
parsesongs(result)
return
def parsesongs(rawstring):
print 'Chocolate Inventory'
print
'---'
print 'Name Rating
Price '
print
'---'
for i in range (0, len(rawstring)):
table = ''
Name = rawstring[i][0]
table = table + Name
for j in range (0, (29 - len(Name))):
table = table + ' '
Rating = rawstring[i][1]
table = table + Rating
for k in range (0, (29 - len(Rating))):
table = table + ' '
Price = str(rawstring[i][2])
table = table + Price
print table
print
'---'
return
errors that occur
press display:
Mod_python error: "PythonHandler mod_python.publisher"
Traceback (most recent call last):
File "/usr/lib/python2.3/site-packages/mod_python/apache.py", line
193, in Dispatch
result = object(req)
File "/usr/lib/python2.3/site-packages/mod_python/publisher.py", line
173, in handler
result = apply(object, (), args)
TypeError: display() takes exactly 1 argument (0 given)
press the addition of the items:
Mod_python error: "PythonHandler mod_python.publisher"
Traceback (most recent call last):
File "/usr/lib/python2.3/site-packages/mod_python/apache.py", line
193, in Dispatch
result = object(req)
File "/usr/lib/python2.3/site-packages/mod_python/publisher.py", line
173, in handler
result = apply(object, (), args)
File
"/home/hayward/public_html/Homework/Python_Executable_Publisher/form.py",
line 11, in addchocolate
cursor.execute(
File "/usr/lib/python2.3/site-packages/MySQLdb/cursors.py", line 137,
in execute
self.errorhandler(self, exc, value)
File "/usr/lib/python2.3/site-packages/MySQLdb/connections.py", line
33, in defaulterrorhandler
raise errorclass, errorvalue
OperationalError: (1054, "Unknown column 'artist' in 'field list'")
Thanks for the help
--
http://mail.python.org/mailman/listinfo/python-list
Putting in an html table
Could someone start me on putting in a table into this code, and some
HTML tags. I would to make the table below the map and have a header at
the top. Thanks for the help.
""" Publisher example """
def query(req, building=""):
# NOTE: best way to understand this is to see the output,
# that is, to "view source" on the generated web page
# read common header for any google mapping
f = file('/home/ta/public_html/maplish/googleHead.html','r')
t = f.read()
f.close()
# define the two buildings we know (because no SQL is done here)
buildings = [ ("cb", "Cambus Office", "-91.552977", "41.659655")
]
buildings += [ ("va/hardlib", "VA/Hardin Library", "-91.549501",
"41.662348") ]
buildings += [ ("hancher", "Hancher Auditorium", "-91.538214",
"41.669529") ]
buildings += [ ("currier", "Currier Hall", "-91.534996",
"41.666163") ]
buildings += [ ("schaeffer", "Schaeffer Hall", "-91.535296",
"41.660969") ]
buildings += [ ("shospital", "South Hospital", "-91.548900",
"41.658885") ]
str = '' # in case no buildings match, use empty string
for x in buildings:
a,b,c,d = x # isolate all the tuple components into a,b,c,d
if building.lower() == a:
# construct javascript, using Python %s to substitute names
and data
# see http://docs.python.org/lib/typesseq-strings.html if
needed
str = 'var bldg%s = new GPoint( %s, %s);\n' % (a, c, d)
str += 'var mrk%s = new GMarker( bldg%s );\n' % (a, a)
str += 'var htm%s = "%s";\n' % (a, b)
str += 'GEvent.addListener(mrk%s,"click",function() {' % a
str += 'mrk%s.openInfoWindowHtml(htm%s); });\n' % (a, a)
str += 'map.addOverlay(mrk%s);\n' % a
# output markers, if any
t = t + str
# then add trailing html to finish page
trail = "//]]> "
t = t + trail
return t
--
http://mail.python.org/mailman/listinfo/python-list
ADD HTML to the code
Could someone tell me how to add some HTML tags to this program. I want
to be able to change the background color, add some headers, and put a
table below the map that will be displayed. Could someone please tell
me how to add this to the current program. Thanks in advance.
Red.py
""" Publisher example """
def query(req, building=""):
# NOTE: best way to understand this is to see the output,
# that is, to "view source" on the generated web page
# read common header for any google mapping
f = file('/home/ta/public_html/maplish/googleHead.html','r')
t = f.read()
f.close()
# define the two buildings we know (because no SQL is done here)
buildings = [ ("cb", "Cambus Office", "-91.552977", "41.659655")
]
buildings += [ ("va/hardlib", "VA/Hardin Library", "-91.549501",
"41.662348") ]
buildings += [ ("hancher", "Hancher Auditorium", "-91.538214",
"41.669529") ]
buildings += [ ("currier", "Currier Hall", "-91.534996",
"41.666163") ]
buildings += [ ("schaeffer", "Schaeffer Hall", "-91.535296",
"41.660969") ]
buildings += [ ("shospital", "South Hospital", "-91.548900",
"41.658885") ]
str = '' # in case no buildings match, use empty string
for x in buildings:
a,b,c,d = x # isolate all the tuple components into a,b,c,d
if building.lower() == a:
# construct javascript, using Python %s to substitute names
and data
# see http://docs.python.org/lib/typesseq-strings.html if
needed
str = 'var bldg%s = new GPoint( %s, %s);\n' % (a, c, d)
str += 'var mrk%s = new GMarker( bldg%s );\n' % (a, a)
str += 'var htm%s = "%s";\n' % (a, b)
str += 'GEvent.addListener(mrk%s,"click",function() {' % a
str += 'mrk%s.openInfoWindowHtml(htm%s); });\n' % (a, a)
str += 'map.addOverlay(mrk%s);\n' % a
# output markers, if any
t = t + str
# then add trailing html to finish page
trail = "//]]> "
t = t + trail
return t
htaccess
SetHandler python-program
PythonHandler mod_python.publisher
PythonDebug On
googleHead.html
http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd";>
http://www.w3.org/1999/xhtml";>
University of Iowa Cambus
http://maps.google.com/maps?file=api&v=1&key=ABQIoq-X4K0kg9eYo1EhqRtUSxRepKXVB5XJtiHJ0W4XJYyDQ5hNnxQKi9AqI9J1B9uwt8TVJptjDwSqPA";
type="text/javascript">
Street Address in Iowa City:
Adding bound methods dynamically...
#!/usr/bin/env python
'''
I want to dynamically add or replace bound methods in a class. I want
the modifications to be immediately effective across all instances,
whether created before or after the class was modified. I need this
to work for both old ('classic') and new style classes, at both 2.3
and 2.4. I of course want to avoid side effects, and to make the
solution as light-weight as possible.
Question for the experts: Is the solution coded in AddBoundMethod()
acceptable to the Pythonian Gods? :) It does seem to work -- tested
at 2.3.5 (RH Linux) and 2.4.1 (WinXP)
Is there a more pythonic way that's as straight forward?
'''
def AddBoundMethod( cls, name, method ):
'''
Dynamically add to the class 'cls' a bound method.
Invoking this method instantly adds (or overwrites) the
bound method identified by 'name' with the code contained in
'method', EVEN FOR PRE-EXISTING INSTANCES OF THE CLASS. The
'method' parameter should be a non-class function that has 'self'
as its first parameter.
'''
try: types
except NameError: import types
#
# this is the crux of this example, short and sweet...
#
exec "%s.%s = types.MethodType( method, None, %s )" \
% ( cls.__name__, name, cls.__name__ )
#
# The remainder (50x longer than the solution!) is test code...
#
# one new-style class...
class NewStyleClass( object ):
def __init__ ( self, objname ):
print "Created a NewStyleClass, id %d, %s" % \
( id( self ), objname ) self.objname = objname
def ExistingMethod( self, msg ):
print "Original ExistingMethod, id %d, %s: '%s'" % \
( id( self ), self.objname, msg )
# one 'classic' style class...
class OldStyleClass:
def __init__ ( self, objname ):
print "Created a OldStyleClass, id %d, %s" % \
( id( self ), objname ) self.objname = objname
def ExistingMethod( self, msg ):
print "Original ExistingMethod, id %d, %s: '%s'" % \
( id( self ), self.objname, msg )
# two non-class functions that *look* like bound methods in a class;
# one returns a value, the other just outputs a string...
def NeverInOriginalClass( self, msg ):
return "Never in original class, id %d, %s: '%s'" % \
( id( self ), self.objname, msg )
def NewExistingMethod( self, msg ):
print "REPLACED ExistingMethod, id %d, %s: '%s'" % \
( id( self ), self.objname, msg )
# a test routine...
def Test( cls ):
print "--- %s --" % \
cls.__name__
print "type of class %s is '%s'" % ( cls.__name__, type( cls ) )
before_change = cls('instance created before change')
print "type of object before_change is '%s'" % type(before_change)
# 'A' shows that we start with an existing method
before_change.ExistingMethod( 'A' )
print "*** Replacing bound method 'ExistingMethod'..."
AddBoundMethod( cls, "ExistingMethod", NewExistingMethod )
after_change = cls( 'instance created AFTER change' )
print "type of after_change is '%s'" % type( after_change )
# 'B' and 'C' show we've replaced an existing method, both on
# pre-existing instances and instances created after using
# AddBoundMethod()
before_change.ExistingMethod( 'B' )
after_change.ExistingMethod( 'C' )
print "*** Adding new bound method 'AddedMethod'..."
AddBoundMethod( after_change.__class__, "AddedMethod",
NeverInOriginalClass )
# 'D' and 'E' show we've added a brand new method, both on
# pre-existing instances and instances created after using
# AddBoundMethod()
print "%s" % before_change.AddedMethod( 'D' )
print "%s" % after_change.AddedMethod( 'E' )
if __name__ == '__main__':
Test( OldStyleClass )
Test( NewStyleClass )
--
http://mail.python.org/mailman/listinfo/python-list
Re: Adding bound methods dynamically... CORRECTED
#!/usr/bin/env python
# Sorry... :} cut/paste error fixed...
'''
I want to dynamically add or replace bound methods in a class. I want
the modifications to be immediately effective across all instances,
whether created before or after the class was modified. I need this
to work for both old ('classic') and new style classes, at both 2.3
and 2.4. I of course want to avoid side effects, and to make the
solution as light-weight as possible.
Question for the experts: Is the solution coded in AddBoundMethod()
acceptable to the Pythonian Gods? :) It does seem to work -- tested
at 2.3.5 (RH Linux) and 2.4.1 (WinXP)
Is there a more pythonic way that's as straight forward?
'''
def AddBoundMethod( cls, name, method ):
'''
Dynamically add to the class 'cls' a bound method.
Invoking this method instantly adds (or overwrites) the
bound method identified by 'name' with the code contained in
'method', EVEN FOR PRE-EXISTING INSTANCES OF THE CLASS. The
'method' parameter should be a non-class function that has 'self'
as its first parameter.
'''
try: types
except NameError: import types
#
# this is the crux of this example, short and sweet...
#
exec "%s.%s = types.MethodType( method, None, %s )" \
% ( cls.__name__, name, cls.__name__ )
#
# The remainder (50x longer than the solution!) is test code...
#
# one new-style class...
class NewStyleClass( object ):
def __init__ ( self, objname ):
print "Created a NewStyleClass, id %d, %s" % \
( id( self ), objname )
self.objname = objname
def ExistingMethod( self, msg ):
print "Original ExistingMethod, id %d, %s: '%s'" % \
( id( self ), self.objname, msg )
# one 'classic' style class...
class OldStyleClass:
def __init__ ( self, objname ):
print "Created a OldStyleClass, id %d, %s" % \
( id( self ), objname )
self.objname = objname
def ExistingMethod( self, msg ):
print "Original ExistingMethod, id %d, %s: '%s'" % \
( id( self ), self.objname, msg )
# two non-class functions that *look* like bound methods in a class;
# one returns a value, the other just outputs a string...
def NeverInOriginalClass( self, msg ):
return "Never in original class, id %d, %s: '%s'" % \
( id( self ), self.objname, msg )
def NewExistingMethod( self, msg ):
print "REPLACED ExistingMethod, id %d, %s: '%s'" % \
( id( self ), self.objname, msg )
# a test routine...
def Test( cls ):
print "--- %s --" % \
cls.__name__
print "type of class %s is '%s'" % ( cls.__name__, type( cls ) )
before_change = cls('instance created before change')
print "type of object before_change is '%s'" % type(before_change)
# 'A' shows that we start with an existing method
before_change.ExistingMethod( 'A' )
print "*** Replacing bound method 'ExistingMethod'..."
AddBoundMethod( cls, "ExistingMethod", NewExistingMethod )
after_change = cls( 'instance created AFTER change' )
print "type of after_change is '%s'" % type( after_change )
# 'B' and 'C' show we've replaced an existing method, both on
# pre-existing instances and instances created after using
# AddBoundMethod()
before_change.ExistingMethod( 'B' )
after_change.ExistingMethod( 'C' )
print "*** Adding new bound method 'AddedMethod'..."
AddBoundMethod( after_change.__class__, "AddedMethod",
NeverInOriginalClass )
# 'D' and 'E' show we've added a brand new method, both on
# pre-existing instances and instances created after using
# AddBoundMethod()
print "%s" % before_change.AddedMethod( 'D' )
print "%s" % after_change.AddedMethod( 'E' )
if __name__ == '__main__':
Test( OldStyleClass )
Test( NewStyleClass )
--
http://mail.python.org/mailman/listinfo/python-list
Re: HELP!! Accessing other machines with an IIS CGI script
Thanks for the info. I'm going to repost this in comp.lang.python as well as in a couple of MS IIS groups with some additional information (code snippets and results). Paul "Roger Upole" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Without knowing what operation fails, it's kind of > difficult to give any meaningful answers. > At what point in the code do you get the error ? > > If IIS runs under a local account, it might not have > permission to access the other machine, or to impersonate > a domain user. > > You might want to set up auditing on the > folder you're trying to list, and see exactly what user > IIS is connecting as (or if it's connecting at all). > >hth >Roger > > > "paulp" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > > Greetings, > > > > I'm working on a CGI program that will run under MS IIS 5.0 and will > > browse folders on three other machines, building HTML pages that will > > provide links to these folders. > > > > Essentially, the CGI will connect to each machine in turn, doing the > > FindFirst/FindNext process based on the current criteria. It will > > select certain files/folders, and build an HTML page as it goes. > > > > The premise is fine. If I run the program from the command line, it > > seems to work fine and I get my HTML code out. I can copy the code > > into a separate file, open it in the browser, and all appears right > > with the world. > > > > However, when I try to run the CGI from the browser itself, I get all > > kinds of problems. The first one I got was a 1312, "A specified logon > > session does not exist. It may have already been terminated." After > > doing some searching, I began to investigate impersonation of a logged > > on user. This produces a different error: 1314, "A required privilege > > is not held by the client." > > > > I've been arguing with this now for several days and the frustration > > level is beginning to get quite high. Has anyone else ever tried this? > > I find it hard to believe that I'm the first to do this. > > > > Of course, one of my problems is that I'm neither an IIS guru nor an > > Admin guru. And we have neither here in the office. > > > > I'm coding this in Python 2.4 and the Windows extensions. I have a > > number of other CGI programs in Python running under IIS that work > > correctly, but those only do database accesses. This one I'm trying to > > put together is the first one to actually do file searches. > > > > I have set the privileges for the logged on account on my IIS box for > > SE_TCB_NAME, SE_CHANGE_NOTIFY_NAME and SE_ASSIGNPRIMARYTOKEN_NAME and > > rebooted. To no avail. I'm not sure if there are additional > > alterations that need to be done to the security policies or not. > > Again, I'm not a guru. > > > > If anyone can give me more information/guidance I would greatly > > appreciate it. If you need more information from me, I will do my best > > to provide it. > > > > TIA, > > > > Paul > > > > > > == Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News== > http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups > = East and West-Coast Server Farms - Total Privacy via Encryption = -- http://mail.python.org/mailman/listinfo/python-list
xmlrpclib with technorati
I'm trying to write a generic weblog update notifier using xmlrpclib, starting with technorati. What I want to do is something like this : XML config file that would look like this: http://mail.python.org/mailman/listinfo/python-list
Re: Python or PHP?
Steve Holden <[EMAIL PROTECTED]> wrote: >Your statement then becomes > >select * from foo where bar=1; drop table foo > >which is clearly not such a good idea. I'm sure Steve is very well aware of this and was just providing a simple and obvious example, nevertheless it might be worth pointing out that anyody who connects their web application to their database as a user that has DROP TABLE privileges, would clearly be in need of a lot more help on basic security concepts than just advice on choosing a programming language. This goes back to the point somebody made earlier on in the thread - many web applications can be implemented as fairly simple wrappers around properly designed databases. "Properly designed" includes giving some thought to table ownership and privileges. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python or PHP?
Steve Holden <[EMAIL PROTECTED]> wrote in message news:<[EMAIL PROTECTED]>... > John Bokma wrote: > > Alan Little wrote: > > > > > >>Steve Holden <[EMAIL PROTECTED]> wrote: > >> > >> > >>>Your statement then becomes > >>> > >>>select * from foo where bar=1; drop table foo > >>> > >>>which is clearly not such a good idea. > >> > >>I'm sure Steve is very well aware of this and was just providing a > >>simple and obvious example, nevertheless it might be worth pointing > >>out that anyody who connects their web application to their database > >>as a user that has DROP TABLE privileges, would clearly be in need of > >>a lot more help on basic security concepts than just advice on > >>choosing a programming language. > > > > > > True. But how does it stop someone who uses inserts? (I exclude the case > > inserts are not needed). Inserts are indeed not needed, if you really don't want to allow them. The web app user connects to a schema that has no direct write privileges on anything. Instead it has execute permissions on stored procedures in another schema that do the writes. In Oracle, at any rate, the stored procedure then runs with the privileges of the schema it is in, but the calling user doesn't need or get those privileges. Over the top in many cases, but it's an extra layer of defence if you want it. > > > > > >>This goes back to the point somebody made earlier on in the thread - > >>many web applications can be implemented as fairly simple wrappers > >>around properly designed databases. "Properly designed" includes > >>giving some thought to table ownership and privileges. > > > > > > One should stop SQL injection always, no matter if the database takes care > > of it or not. There is no excuse (like, yeah, but I set up the privileges > > right) for allowing SQL injection, ever. Wasn't suggesting that for a moment. > > > Correct. If a thing can't go wrong, it won't. > > In security several levels of defense are better than just one, so > database authorization and SQL injection removal should be considered > complimentary techniques of a "belt and braces" (US: "belt and > suspenders") approach. > > regards > Steve I completely agree of course. Do both. -- http://mail.python.org/mailman/listinfo/python-list
ftplib errors/exceptions
I'm new to Python and I am writing a simple FTP client. I am having trouble handling errors like connection refused, invalid username or password, and the like. I can use a try exception block like thistry: ftp=FTP('some_server')
ftp.login() # more linesexcept: print "An error has occured.\n"This works fine to supress the errors, but I would like to be able to narrow the errors down so that I can print 'invalid username or password' or 'connection refused' rather than simply 'An error has occured'. How would I go about narrowing down which errors occur?
Thanks in advance
--
http://mail.python.org/mailman/listinfo/python-list
Hooking any/all 'calls'
In Python 2.4 or 2.5, what is the easiest way to hook any and all callables such that designated code is executed at the very start and end of each call? (Yes, I'm trying to come up with a little debugging tool!:) Is there a single metaclass who's "__call__" method can be wrapped to do this? TIA, -k -- http://mail.python.org/mailman/listinfo/python-list
Re: Hooking any/all 'calls'
Thanks, Robert! That was exactly what I was looking for. -k "fumanchu" <[EMAIL PROTECTED]> wrote: >Kevin Little wrote: >> In Python 2.4 or 2.5, what is the easiest way to hook any and all >> callables such that designated code is executed at the very start and >> end of each call? (Yes, I'm trying to come up with a little debugging >> tool!:) Is there a single metaclass who's "__call__" method can be >> wrapped to do this? > >You probably want sys.settrace, which is specifically designed for >creating debuggers, and is the basis for pdb, the debugger in the >standard library. See >http://docs.python.org/lib/module-sys.html#l2h-5159 > >Feel free also to look through my own debugging aid (for clues on how >to implement your own, or just to use for your needs): >http://projects.amor.org/misc/wiki/PyConquer > > >Robert Brewer >System Architect >Amor Ministries >[EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Re: crash while using PyCharm / Python3
Adam wrote: There ought to be a way to just reinstall the graphics subsystem rather than an all-or-none installation approach. Yes you can. Did it for a borked install of the nVidia driver. reference this: <https://wiki.ubuntu.com/X/Troubleshooting/VideoDriverDetection#Problem:_Need_to_purge_-fglrx> -- Take care, Jonathan --- LITTLE WORKS STUDIO http://www.LittleWorksStudio.com -- https://mail.python.org/mailman/listinfo/python-list
Re: crash while using PyCharm / Python3
Adam wrote: "Adam" wrote in message news:[email protected]... "Jonathan N. Little" wrote in message news:[email protected]... Adam wrote: There ought to be a way to just reinstall the graphics subsystem rather than an all-or-none installation approach. Yes you can. Did it for a borked install of the nVidia driver. reference this: <https://wiki.ubuntu.com/X/Troubleshooting/VideoDriverDetection#Problem:_Need_to_purge_-fglrx> Thanks, even after doing the following... Problem: Need to purge -fglrx Typically, the following manual commands will properly uninstall -fglrx: $ sudo apt-get remove --purge xorg-driver-fglrx fglrx* $ sudo apt-get install --reinstall libgl1-mesa-glx libgl1-mesa-dri xserver-xorg-core $ sudo dpkg-reconfigure xserver-xorg I still get that dreaded "The system is running in low-graphics mode" error. And, recovery mode failsafeX and Ctrl+Alt+F1 hangs with the following... Initializing built-in extension MIT-SCREEN-SAVER Initializing built-in extension DOUBLE-BUFFER Initializing built-in extension RECORD Initializing built-in extension DPMS Initializing built-in extension Present Initializing built-in extension DRI3 Initializing built-in extension X-Resource Initializing built-in extension XVideo Initializing built-in extension XVideo-MotionCompensation Initializing built-in extension SELinux Initializing built-in extension XFree86-VidModeExtension Initializing built-in extension XFree86-DGA Initializing built-in extension XFree86-DRI Initializing built-in extension DRI2 Loading extension GLX After trying the following... http://askubuntu.com/questions/577093/how-to-install-gnome-desktop $ sudo apt-get update $ sudo apt-get install gnome-shell http://tipsonubuntu.com/2014/06/06/change-display-manager-ubuntu-14-04/ $ sudo dpkg-reconfigure lightdm Not sure about ATI, but when you purge the nVidia driver it takes Unity with it so I had to reinstall unity-desktop afterwards. If you want lightdm but are now using gdm, maybe it happened because unity-desktop was uninstalled and you just installed gnome-shell, your can reset: sudo dpkg-reconfigure gdm and select lightdm from the list. -- Take care, Jonathan --- LITTLE WORKS STUDIO http://www.LittleWorksStudio.com -- https://mail.python.org/mailman/listinfo/python-list
Re: crash while using PyCharm / Python3
Adam wrote: Sure glad I did not reinstall Ubuntu. Whew!! Unless you really-really-really screw things up, you usually do not have to. Linux is not Windows ;-) Even if you had to, with /home on its own partition a reinstall would not have been an issue, you just have to choose the "Something Else" on partitioning and only format the "/" and set the "/home" partition mount point and NOT FORMAT it. A tip: If you use gparted or e2label and give partitions labels. Makes moving partitions and data easier... sda1 "12.04-root" sda5 "old-home" sdb1 "14.04-root" sdb5 "new-home" So from a live session when I mount both drives it is easy to keep things straight when I copy my profiles from old drive on sda to new drive with newer version of Ubuntu on sdb... -- Take care, Jonathan --- LITTLE WORKS STUDIO http://www.LittleWorksStudio.com -- https://mail.python.org/mailman/listinfo/python-list
Re: crash while using PyCharm / Python3
Adam wrote: Thanks, but why fix if it ain't broke?:-) No reason to. -- Take care, Jonathan --- LITTLE WORKS STUDIO http://www.LittleWorksStudio.com -- https://mail.python.org/mailman/listinfo/python-list
Re: argsparse: allowing --version without mandatory options
Loris Bennett wrote:
> "Loris Bennett" writes:
>
>> Hi,
>>
>> I am writing a program for the command-line which uses 'argsparse'. I
>> want to make some options mandatory by setting 'required=True', but
>> still allow the program to run with the option '--version' (which just
>> shows the version and then exits) even if the mandatory options are
>> missing.
>>
>> Is there a standard way of doing this?
>
> I see that instead of setting required to 'True' I can use an expression
> which checks whether '--version' has been given:
What I do is separate it into two functions. First function that sets up
the parser object and returns the parser object:
def make_parser() -> argparse.ArgumentParser:
parser = argparse.ArgumentParser( ... )
...
return parser
The code is similar to yours below, but for version my action references
an f string variable:
parser.add_argument(
"-v", "--version", action="version",
version=f"{APP_NAME} v{__version__}"
)
I typically have the optional args set to a default value, null string
or None. Then the second function which my main() calls this function
which returns a tuple of arg values here is one example:
def get_program_args() -> tuple:
parser = make_parser()
args = parser.parse_args()
return args.action, args.profile, args.log_level
def main():
# parser args
action, profile_name, log_level = get_program_args()
...
Works for me.
> parser.add_argument(
> "uid", nargs="+",
> help="UIDs to send mail to"
> )
> parser.add_argument(
> '-s', '--subject', dest='subject', required=not '--version' in
> sys.argv,
> help="subject of email"
> )
> parser.add_argument(
> '-c', '--content_file', dest='content_file', required=not '--version'
> in sys.argv,
> help="file containing mail contents (without salutation or signature)"
> )
> parser.add_argument(
> '--version', action='store_true', dest='version',
> help="print version"
>
> However, with the above, I still need to specify the mandatory argument,
> even if I only want to see the version.
>
> I guess I'll just have to change
>
> nargs="+"
>
> to
>
> nargs="*"
>
> and check explicitly whether any arguments have been given.
>
> Seems odd to me though that there is not a standard way of implementing
> '--version' which works like '--help' does.
>
> Cheers,
>
> Loris
>
--
Take care,
Jonathan
---
LITTLE WORKS STUDIO
http://www.LittleWorksStudio.com
--
https://mail.python.org/mailman3//lists/python-list.python.org
