Instance method for converting int to str - str() and __str__()
I was wondering if there is any resource that explains why certain methods like str() and type() were implemented the way they are, rather than .to_string() or .type() instance/object methods. I find instance/object methods more intuitive for this cases, but I am wondering why it wasn't implemented it like that. I know there are equivalents like __str__() and __class__ , but passing object to str() or type() seems more popular. Any resources for reading or some background information would be helpful. - CS -- https://mail.python.org/mailman/listinfo/python-list
Re: sys path modification
Modules are installed, but they are in a different directory than standard modules directory. I considered an option to add a site specific directory, but I want to make module path application specific rather than installing it in system-wide directory. virtualenv is one option, but that means anyone who wants to run this particular script will need to activate virtualenv each time. I thought allowing application to find/use it's dependencies would be easier. Are there any other options? On Mon, Jul 27, 2015 at 12:45 PM, Ned Batchelder wrote: > On Monday, July 27, 2015 at 1:24:50 PM UTC-4, neubyr wrote: > > I am trying to understand sys.path working and best practices for > managing it within a program or script. Is it fine to modify sys.path using > sys.path.insert(0, EXT_MODULES_DIR)? One stackoverflow answer - > http://stackoverflow.com/a/10097543 - suggests that it may break external > 3'rd party code as by convention first item of sys.path list, path[0], is > the directory containing the script that was used to invoke the Python > interpreter. So what are best practices to prepend sys.path in the program > itself? Any further elaboration would be helpful. > > The best practice is not to modify sys.path at all, and instead to install > modules you need to import. That way they can be imported without > resorting > to sys.path fiddling in the first place. > > Is there a reason you can't install the modules? Maybe we can help solve > that. > > --Ned. > > -- > https://mail.python.org/mailman/listinfo/python-list > -- https://mail.python.org/mailman/listinfo/python-list
sys path modification
I am trying to understand sys.path working and best practices for managing it within a program or script. Is it fine to modify sys.path using sys.path.insert(0, EXT_MODULES_DIR)? One stackoverflow answer - http://stackoverflow.com/a/10097543 - suggests that it may break external 3'rd party code as by convention first item of sys.path list, path[0], is the directory containing the script that was used to invoke the Python interpreter. So what are best practices to prepend sys.path in the program itself? Any further elaboration would be helpful. - thanks, N -- https://mail.python.org/mailman/listinfo/python-list
Re: MIMEText encode error - Python 2.6.6
On Tue, Sep 6, 2011 at 5:05 PM, MRAB wrote: > On 06/09/2011 22:52, neubyr wrote: >> >> I am trying to write a program which can email file's content using >> smtplib. I am getting following error while using Python 2.6.6 >> version. >> >> {{{ >> File "./killed_jobs.py", line 88, in sendmail >> msg = MIMEText(ipfile.read, 'plain') >> File "/home/ssp/sge/python/2.6.6/lib/python2.6/email/mime/text.py", >> line 30, in __init__ >> self.set_payload(_text, _charset) >> File "/home/ssp/sge/python/2.6.6/lib/python2.6/email/message.py", >> line 224, in set_payload >> self.set_charset(charset) >> File "/home/ssp/sge/python/2.6.6/lib/python2.6/email/message.py", >> line 266, in set_charset >> cte(self) >> File "/home/ssp/sge/python/2.6.6/lib/python2.6/email/encoders.py", >> line 73, in encode_7or8bit >> orig.encode('ascii') >> AttributeError: 'builtin_function_or_method' object has no attribute >> 'encode' >> >> }}} >> >> >> I am referring to email examples on the doc site >> >> http://docs.python.org/release/2.6.6/library/email-examples.html#email-examples >> . Following is the msg object part in my code: >> >> {{{ >> ... >> ... >> def sendmail(inputfile): >> ipfile = open(inputfile, 'r') >> msg = MIMEText(ipfile.read, 'plain') >> ipfile.close() >> >> ... >> ... >> }}} >> >> I have tried setting subtype and chartype separately as mentioned here >> - http://docs.python.org/release/2.6.6/library/email.mime.html, but >> the error remains same. Any help on what might be wrong here? >> > The docs say: > > MIMEText(_text[, _subtype[, _charset]]) > > ... _text is the string for the payload ... > > You're passing ipfile.read, which is the read method of the file. You > should be passing the string returned by calling ipfile.read, ie > ipfile.read(). > -- > thanks got pointing that.. -- -- http://mail.python.org/mailman/listinfo/python-list
MIMEText encode error - Python 2.6.6
I am trying to write a program which can email file's content using smtplib. I am getting following error while using Python 2.6.6 version. {{{ File "./killed_jobs.py", line 88, in sendmail msg = MIMEText(ipfile.read, 'plain') File "/home/ssp/sge/python/2.6.6/lib/python2.6/email/mime/text.py", line 30, in __init__ self.set_payload(_text, _charset) File "/home/ssp/sge/python/2.6.6/lib/python2.6/email/message.py", line 224, in set_payload self.set_charset(charset) File "/home/ssp/sge/python/2.6.6/lib/python2.6/email/message.py", line 266, in set_charset cte(self) File "/home/ssp/sge/python/2.6.6/lib/python2.6/email/encoders.py", line 73, in encode_7or8bit orig.encode('ascii') AttributeError: 'builtin_function_or_method' object has no attribute 'encode' }}} I am referring to email examples on the doc site http://docs.python.org/release/2.6.6/library/email-examples.html#email-examples . Following is the msg object part in my code: {{{ ... ... def sendmail(inputfile): ipfile = open(inputfile, 'r') msg = MIMEText(ipfile.read, 'plain') ipfile.close() ... ... }}} I have tried setting subtype and chartype separately as mentioned here - http://docs.python.org/release/2.6.6/library/email.mime.html, but the error remains same. Any help on what might be wrong here? thanks, neuby.r -- http://mail.python.org/mailman/listinfo/python-list