Eurosymbol in xml document
Hi, i'm new here in this list. i'm developing a little program using an xml document. So far it's easy going, but when parsing an xml document which contains the EURO symbol ('€') then I get an error: UnicodeEncodeError: 'charmap' codec can't encode character u'\xa4' in position 11834: character maps to the relevant piece of code is: from xml.dom.minidom import Document, parse, parseString ... doc = parse(inFIleName) [EMAIL PROTECTED] usexml $ locale [EMAIL PROTECTED] LC_CTYPE="[EMAIL PROTECTED]" LC_NUMERIC="[EMAIL PROTECTED]" LC_TIME="[EMAIL PROTECTED]" LC_COLLATE="[EMAIL PROTECTED]" LC_MONETARY="[EMAIL PROTECTED]" LC_MESSAGES="[EMAIL PROTECTED]" LC_PAPER="[EMAIL PROTECTED]" LC_NAME="[EMAIL PROTECTED]" LC_ADDRESS="[EMAIL PROTECTED]" LC_TELEPHONE="[EMAIL PROTECTED]" LC_MEASUREMENT="[EMAIL PROTECTED]" LC_IDENTIFICATION="[EMAIL PROTECTED]" [EMAIL PROTECTED] any help appreciated Hellmut -- Dr. Hellmut Weber [EMAIL PROTECTED] Degenfeldstraße 2 tel +49-89-3081172 D-80803 München-Schwabing mobil +49-172-8450321 please: No DOCs, no PPTs. why: tinyurl.com/cbgq -- http://mail.python.org/mailman/listinfo/python-list
Re: Eurosymbol in xml document
Hi, thanks to all of you who have sent me helpful information. I'm diving into the secrets of unicode. It seems the crucial point was, that seemingly during the installation of the programming environment eric the file *** /usr/lib/python2.4/site-packages/sitecustomize.py *** has been modified. I found that file mentioned in the excellent online book 'Diving into python' Thanks again + happy pythoning Hellmut -- Dr. Hellmut Weber [EMAIL PROTECTED] Degenfeldstraße 2 tel +49-89-3081172 D-80803 München-Schwabing mobil +49-172-8450321 please: No DOCs, no PPTs. why: tinyurl.com/cbgq -- http://mail.python.org/mailman/listinfo/python-list
Access function name from within a function
Hi, i would liek to define an error routine which print amongs other things the name of the function from which it has been called. Having tried def foo(): print dir() and all other ideas which came to my (rather python newbie) mind. Googling too did not show me a possibility. IOW what I'm looking for is: def bar(): name = some_function(some-parameter) print name should print 'bar' Any ideas appreciated Hellmut -- Dr. Hellmut Weber [EMAIL PROTECTED] Degenfeldstraße 2 tel +49-89-3081172 D-80803 München-Schwabing mobil +49-172-8450321 please: No DOCs, no PPTs. why: tinyurl.com/cbgq -- http://mail.python.org/mailman/listinfo/python-list
integer and string compare, is that correct?
Hi, being a causal python user (who likes the language quite a lot) it took me a while to realize the following: l...@sylvester py_count $ python Python 2.6.3 (r263:75183, Oct 26 2009, 12:34:23) [GCC 4.4.1] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> max = '5' >>> n = 5 >>> n >= max False >>> n + max Traceback (most recent call last): File "", line 1, in TypeError: unsupported operand type(s) for +: 'int' and 'str' >>> Section 5.9 Comparison describes this. Can someone give me examples of use cases TIA Hellmut -- Dr. Hellmut Weber m...@hellmutweber.de Degenfeldstraße 2 tel +49-89-3081172 D-80803 München-Schwabing mobil +49-172-8450321 please: No DOCs, no PPTs. why: tinyurl.com/cbgq -- http://mail.python.org/mailman/listinfo/python-list
Re: integer and string compare, is that correct?
Hi, thanks to all who answered. I'm using Python 2.6.5 on my machine and consulted the corresponding documentation. I do appreciate the modified definition of python 3, that seems much more reasonable. Thanks for indicating. Greetings from Munich in Winter Hellmut Am 10.01.2010 17:34, schrieb Nobody: Hellmut Weber wrote: being a causal python user (who likes the language quite a lot) it took me a while to realize the following: >>> max = '5' >>> n = 5 >>> n>= max False Section 5.9 Comparison describes this. Can someone give me examples of use cases Peter Otten wrote: The use cases for an order that works across types like int and str are weak to non-existent. Implementing it was considered a mistake and has been fixed in Python 3: 5> "5" Traceback (most recent call last): File "", line 1, in TypeError: unorderable types: int()> str() If you actually need to perform comparisons across types, you can rely upon the fact that tuple comparisons are non-strict and use e.g.: > a = 5 > b = '5' > (type(a).__name__, a)< (type(b).__name__, b) True > (type(a).__name__, a)> (type(b).__name__, b) False The second elements will only be compared if the first elements are equal (i.e. the values have the same type). -- Dr. Hellmut Weber m...@hellmutweber.de Degenfeldstraße 2 tel +49-89-3081172 D-80803 München-Schwabing mobil +49-172-8450321 please: No DOCs, no PPTs. why: tinyurl.com/cbgq -- http://mail.python.org/mailman/listinfo/python-list
Accessing the name of an actual parameter
Hi, consider the following piece of code, please - - def f(param): nameOfParam = ??? # here I want to access the name of the variable # which was given as parameter to the function print nameOfParam, param return if __name__ == __main__: a = 1 f(a) b = 'abcd' f(a) - - The output should be: 'a' 1 'b' 'abcd' - - I tried to look at globals() and locals(), gave a look to the frames (sys._getframe(0) and sys._getframe(1), but did not see a possibility to access the information a want How can this be done? TIA Hellmut -- Dr. Hellmut Weber m...@hellmutweber.de Degenfeldstraße 2 tel +49-89-3081172 D-80803 München-Schwabing mobil +49-172-8450321 please: No DOCs, no PPTs. why: tinyurl.com/cbgq -- http://mail.python.org/mailman/listinfo/python-list
Re: A tool for find dependencies relationships behind Python projects
Hi Victor, I would be intereseted to use your tool ;-) My system is Sabayon-5.1 on Lenovo T61. Trying for the first time easy_install I get the following error: r...@sylvester ~ # easy_install gluttony Searching for gluttony Reading http://pypi.python.org/simple/gluttony/ Reading http://code.google.com/p/python-gluttony/ Best match: Gluttony 0.3 Downloading http://pypi.python.org/packages/source/G/Gluttony/Gluttony-0.3.zip#md5=c7774d4fcc0402097f90dc81186de465 Processing Gluttony-0.3.zip Running Gluttony-0.3/setup.py -q bdist_egg --dist-dir /tmp/easy_install-uPz7qO/Gluttony-0.3/egg-dist-tmp-CJI_LD Traceback (most recent call last): File "/usr/bin/easy_install", line 9, in load_entry_point('distribute==0.6.8', 'console_scripts', 'easy_install')() File "/usr/lib64/python2.6/site-packages/setuptools/command/easy_install.py", line 1708, in main with_ei_usage(lambda: File "/usr/lib64/python2.6/site-packages/setuptools/command/easy_install.py", line 1696, in with_ei_usage return f() File "/usr/lib64/python2.6/site-packages/setuptools/command/easy_install.py", line 1712, in distclass=DistributionWithoutHelpCommands, **kw File "/usr/lib64/python2.6/distutils/core.py", line 152, in setup dist.run_commands() File "/usr/lib64/python2.6/distutils/dist.py", line 975, in run_commands self.run_command(cmd) File "/usr/lib64/python2.6/distutils/dist.py", line 995, in run_command cmd_obj.run() File "/usr/lib64/python2.6/site-packages/setuptools/command/easy_install.py", line 236, in run self.easy_install(spec, not self.no_deps) File "/usr/lib64/python2.6/site-packages/setuptools/command/easy_install.py", line 471, in easy_install return self.install_item(spec, dist.location, tmpdir, deps) File "/usr/lib64/python2.6/site-packages/setuptools/command/easy_install.py", line 501, in install_item dists = self.install_eggs(spec, download, tmpdir) File "/usr/lib64/python2.6/site-packages/setuptools/command/easy_install.py", line 680, in install_eggs return self.build_and_install(setup_script, setup_base) File "/usr/lib64/python2.6/site-packages/setuptools/command/easy_install.py", line 957, in build_and_install self.run_setup(setup_script, setup_base, args) File "/usr/lib64/python2.6/site-packages/setuptools/command/easy_install.py", line 946, in run_setup run_setup(setup_script, args) File "/usr/lib64/python2.6/site-packages/setuptools/sandbox.py", line 29, in run_setup lambda: execfile( File "/usr/lib64/python2.6/site-packages/setuptools/sandbox.py", line 70, in run return func() File "/usr/lib64/python2.6/site-packages/setuptools/sandbox.py", line 31, in {'__file__':setup_script, '__name__':'__main__'} File "setup.py", line 9, in File "/tmp/easy_install-uPz7qO/Gluttony-0.3/gluttony/__init__.py", line 1, in # File "/tmp/easy_install-uPz7qO/Gluttony-0.3/gluttony/gluttony.py", line 13, in ImportError: No module named pip.log r...@sylvester ~ # I emerged app-misc/pip, but that didn't help, the error remains the same What is missing? Any help appreciated Best regards Hellmut Am 19.02.2010 17:16, schrieb Victor Lin: Hi, I just wrote a tool for drawing dependencies relationships diagram of Python project on Pypi. Here is the home page of the tool: http://code.google.com/p/python-gluttony/ Some examples: Sprox: http://static.ez2learn.com/gluttony/sprox_dot.png TurboGears2: http://static.ez2learn.com/gluttony/tg2_dot.png Hope this could be helpful :P Regards. Victor Lin. -- Dr. Hellmut Weber m...@hellmutweber.de Degenfeldstraße 2 tel +49-89-3081172 D-80803 München-Schwabing mobil +49-172-8450321 please: No DOCs, no PPTs. why: tinyurl.com/cbgq -- http://mail.python.org/mailman/listinfo/python-list
logging: local functions ==> loss of lineno
Hi Vinay Sajip, I'm very glad discoverd your logging module ;-) (That's what I would have liked 25 years ago when I was working as a technical software developper!) Now I'm writing just some personal tools, I like python and want to use logging on a regular basis. Logging works very well giving the filename and line number of the point where it is called. As long as I use the loggers directly. BUT when I have to wrap the logger call in some other function, I always get file name and line number of the call of the logger inside the wrapping function. Is there a possibility to get this information in this situation too? TIA Hellmut -- Dr. Hellmut Weber m...@hellmutweber.de Degenfeldstraße 2 tel +49-89-3081172 D-80803 München-Schwabing mobil +49-172-8450321 please: No DOCs, no PPTs. why: tinyurl.com/cbgq -- http://mail.python.org/mailman/listinfo/python-list
Re: logging: local functions ==> loss of lineno
Am 11.03.2010 12:14, schrieb Peter Otten: Hellmut Weber wrote: Logging works very well giving the filename and line number of the point where it is called. As long as I use the loggers directly. BUT when I have to wrap the logger call in some other function, I always get file name and line number of the call of the logger inside the wrapping function. Is there a possibility to get this information in this situation too? The official way is probably to write a custom Logger class that overrides the findCaller() method. Below is a hack that monkey-patches the logging._srcfile attribute to ignore user-specified modules in the call stack: $ cat wrapper.py import logging import os import sys logger = logging.getLogger() class SrcFile(object): def __init__(self, exclude_files): self.files = set(exclude_files) def __eq__(self, other): return other in self.files def fixname(filename): if filename.lower().endswith((".pyc", ".pyo")): filename = filename[:-4] + ".py" return os.path.normcase(filename) if "--monkey" in sys.argv: print "patching" logging._srcfile = SrcFile([logging._srcfile, fixname(__file__)]) def warn(*args, **kw): logger.warn(*args, **kw) $ cat main.py import logging logging.basicConfig(format="%(filename)s<%(lineno)s>: %(message)s") import wrapper wrapper.warn("foo") wrapper.warn("bar") wrapper.warn("baz") $ python main.py wrapper.py<23>: foo wrapper.py<23>: bar wrapper.py<23>: baz $ python main.py --monkey patching main.py<4>: foo main.py<5>: bar main.py<6>: baz $ python -V Python 2.6.4 Peter Hi Peter, thanks for your help ;-) I've been offline for a few days so I found your message only today. I'll try your proposal tomorrow. Thanks again Hellmut -- Dr. Hellmut Weber m...@hellmutweber.de Degenfeldstraße 2 tel +49-89-3081172 D-80803 München-Schwabing mobil +49-172-8450321 please: No DOCs, no PPTs. why: tinyurl.com/cbgq -- http://mail.python.org/mailman/listinfo/python-list
Re: A tool for find dependencies relationships behind Python projects
Am 24.02.2010 18:49, schrieb Victor Lin: On 2月23日, 上午12時32分, Hellmut Weber wrote: Hi Victor, I would be intereseted to use your tool ;-) My system is Sabayon-5.1 on Lenovo T61. Trying for the first time easy_install I get the following error: r...@sylvester ~ # easy_install gluttony Searching for gluttony Readinghttp://pypi.python.org/simple/gluttony/ Readinghttp://code.google.com/p/python-gluttony/ Best match: Gluttony 0.3 Downloadinghttp://pypi.python.org/packages/source/G/Gluttony/Gluttony-0.3.zip#md... Processing Gluttony-0.3.zip Running Gluttony-0.3/setup.py -q bdist_egg --dist-dir /tmp/easy_install-uPz7qO/Gluttony-0.3/egg-dist-tmp-CJI_LD Traceback (most recent call last): File "/usr/bin/easy_install", line 9, in load_entry_point('distribute==0.6.8', 'console_scripts', 'easy_install')() File "/usr/lib64/python2.6/site-packages/setuptools/command/easy_install.py", line 1708, in main with_ei_usage(lambda: File "/usr/lib64/python2.6/site-packages/setuptools/command/easy_install.py", line 1696, in with_ei_usage return f() File "/usr/lib64/python2.6/site-packages/setuptools/command/easy_install.py", line 1712, in distclass=DistributionWithoutHelpCommands, **kw File "/usr/lib64/python2.6/distutils/core.py", line 152, in setup dist.run_commands() File "/usr/lib64/python2.6/distutils/dist.py", line 975, in run_commands self.run_command(cmd) File "/usr/lib64/python2.6/distutils/dist.py", line 995, in run_command cmd_obj.run() File "/usr/lib64/python2.6/site-packages/setuptools/command/easy_install.py", line 236, in run self.easy_install(spec, not self.no_deps) File "/usr/lib64/python2.6/site-packages/setuptools/command/easy_install.py", line 471, in easy_install return self.install_item(spec, dist.location, tmpdir, deps) File "/usr/lib64/python2.6/site-packages/setuptools/command/easy_install.py", line 501, in install_item dists = self.install_eggs(spec, download, tmpdir) File "/usr/lib64/python2.6/site-packages/setuptools/command/easy_install.py", line 680, in install_eggs return self.build_and_install(setup_script, setup_base) File "/usr/lib64/python2.6/site-packages/setuptools/command/easy_install.py", line 957, in build_and_install self.run_setup(setup_script, setup_base, args) File "/usr/lib64/python2.6/site-packages/setuptools/command/easy_install.py", line 946, in run_setup run_setup(setup_script, args) File "/usr/lib64/python2.6/site-packages/setuptools/sandbox.py", line 29, in run_setup lambda: execfile( File "/usr/lib64/python2.6/site-packages/setuptools/sandbox.py", line 70, in run return func() File "/usr/lib64/python2.6/site-packages/setuptools/sandbox.py", line 31, in {'__file__':setup_script, '__name__':'__main__'} File "setup.py", line 9, in File "/tmp/easy_install-uPz7qO/Gluttony-0.3/gluttony/__init__.py", line 1, in # File "/tmp/easy_install-uPz7qO/Gluttony-0.3/gluttony/gluttony.py", line 13, in ImportError: No module named pip.log r...@sylvester ~ # I emerged app-misc/pip, but that didn't help, the error remains the same What is missing? Any help appreciated Best regards Hellmut Am 19.02.2010 17:16, schrieb Victor Lin: Hi, I just wrote a tool for drawing dependencies relationships diagram of Python project on Pypi. Here is the home page of the tool: http://code.google.com/p/python-gluttony/ Some examples: Sprox: http://static.ez2learn.com/gluttony/sprox_dot.png TurboGears2: http://static.ez2learn.com/gluttony/tg2_dot.png Hope this could be helpful :P Regards. Victor Lin. -- Dr. Hellmut Weber m...@hellmutweber.de Degenfeldstraße 2 tel +49-89-3081172 D-80803 München-Schwabing mobil +49-172-8450321 please: No DOCs, no PPTs. why: tinyurl.com/cbgq Hi, That is a mistake I made in when I am making the distribute. Thanks your reporting. I have already fixed the problem and released Gluttony 0.4, and I tried to install that, it works fine. Victor Lin. Hi Victor, thanks for your message. Sorry I'm so late to answer, I've been offline for a while and didn't remember not to have answered. ,-( I downloaded Gluttony-0.4 and the installation was done in a few seconds. It works just fine ;-) Thanks for providing this tool Cheers Hellmut -- Dr. Hellmut Weber m...@hellmutweber.de Degenfeldstraße 2 tel +49-89-3081172 D-80803 München-Schwabing mobil +49-172-8450321 please: No DOCs, no PPTs. why: tinyurl.com/cbgq -- http://mail.python.org/mailman/listinfo/python-list
Re: logging: local functions ==> loss of lineno
Am 11.03.2010 12:14, schrieb Peter Otten: Hellmut Weber wrote: Logging works very well giving the filename and line number of the point where it is called. As long as I use the loggers directly. BUT when I have to wrap the logger call in some other function, I always get file name and line number of the call of the logger inside the wrapping function. Is there a possibility to get this information in this situation too? The official way is probably to write a custom Logger class that overrides the findCaller() method. Below is a hack that monkey-patches the logging._srcfile attribute to ignore user-specified modules in the call stack: $ cat wrapper.py import logging import os import sys logger = logging.getLogger() class SrcFile(object): def __init__(self, exclude_files): self.files = set(exclude_files) def __eq__(self, other): return other in self.files def fixname(filename): if filename.lower().endswith((".pyc", ".pyo")): filename = filename[:-4] + ".py" return os.path.normcase(filename) if "--monkey" in sys.argv: print "patching" logging._srcfile = SrcFile([logging._srcfile, fixname(__file__)]) def warn(*args, **kw): logger.warn(*args, **kw) $ cat main.py import logging logging.basicConfig(format="%(filename)s<%(lineno)s>: %(message)s") import wrapper wrapper.warn("foo") wrapper.warn("bar") wrapper.warn("baz") $ python main.py wrapper.py<23>: foo wrapper.py<23>: bar wrapper.py<23>: baz $ python main.py --monkey patching main.py<4>: foo main.py<5>: bar main.py<6>: baz $ python -V Python 2.6.4 Peter Hi Peter, your hack is exactly what I was looking for. It permits to configure my logging messages as I want, e.g. using different colors for different classes of messages. I do not yet understand all details WHY it is working but suppose some study of the logging module will help me to understand. Thank you very much -- Dr. Hellmut Weber m...@hellmutweber.de Degenfeldstraße 2 tel +49-89-3081172 D-80803 München-Schwabing mobil +49-172-8450321 please: No DOCs, no PPTs. why: tinyurl.com/cbgq -- http://mail.python.org/mailman/listinfo/python-list
Re: logging: local functions ==> loss of lineno
ilename': previousFrame.f_code.co_filename }) def error_log(self, msg, *args, **kwargs): previousFrame = inspect.currentframe().f_back locLogg._logger.error(str(level_color['error'])+msg+pc_norm + \ ' ' + argskw_2_string(*args, **kwargs), extra={'custom_lineno':previousFrame.f_lineno, 'custom_filename': previousFrame.f_code.co_filename }) def fatal_log(self, msg, *args, **kwargs): previousFrame = inspect.currentframe().f_back locLogg._logger.fatal(str(level_color['fatal'])+msg+pc_norm + \ ' ' + argskw_2_string(*args, **kwargs), extra={'custom_lineno':previousFrame.f_lineno, 'custom_filename': previousFrame.f_code.co_filename }) # --- Permit definition of a tracing decorator --- from decorator import decorator @decorator def trace(f, *args, **kw): print "@trace: calling %s with args %s, %s" % (f.func_name, args, kw) return f(*args, **kw) # cf. doc of Michele Simoniato's decorator module if __name__ == '__main__': _logger = logging.getLogger('jmp_logg__main__') foo = locLogg(_logger) foo.init_logging() foo.info_log('a foo info') foo.info_log('another bar info', 1,2,3, a=11, b=22, c=44) foo.debug_log('a debug bar info', 'a', '1aA', qwe=2, asd=99) foo.warn_log('a test info', 'ggg', '2U2', yxcv=2, asdf=99) try: b = 123 c = 0 a = b / c except: foo.fatal_log('Division by zero', b=123, c=0) l...@sylvester hw_logg $ cat test_loclogg.py #!/bin/env python # -*- coding: utf-8 -*- import logging _logger = logging.getLogger() import sys pyDevelDir = '/home/leo/leo/brbeit/py-devel/Modules' sys.path.append(pyDevelDir) from hw_logg.loc_logg import locLogg foo = locLogg(_logger) foo.init_logging( loclogg_output='both', loclogg_dblevel='DEBUG') import loc_module as jm foo.info_log('First info with args in string: %d %d %d' % (1,2,3)) foo.warn_log('First warning') foo.debug_log('First debug message TestTestTest', '--', 4,5,6, 12*25, d=34, e='qwe') foo.debug_log('Before calling jm.doIt()') jm.doIt(True) foo.info_log('Second info with kwargs separate:', a=11,b=22,c=33) x = jm.MyClass(1, 2, 'abc') x.mymethod() x.mymethod(123, 234, a=1, b=2, c=3) try: jm.doIt(0) except Exception, e: foo.error_log(str(e), 1,5,8) foo.fatal_log('Fatal message') l...@sylvester hw_logg $ cat loc_module.py # -*- coding: utf-8 -*- import logging _logger = logging.getLogger('jmp_logger') import sys pyDevelDir = '/home/leo/leo/brbeit/py-devel/Modules' sys.path.append(pyDevelDir) from hw_logg.loc_logg import locLogg, trace foo = locLogg(_logger) foo.info_log("Start importing "+__name__) def doIt(yn=None): foo.debug_log("doin' stuff, yn =", str(yn)) # logLevel at calling point ! print '=> Output from doIt:', yn #do stuff...but suppose an error occurs? if yn: foo.info_log('yn: good value') else: raise TypeError, "bogus type error for testing" class MyClass(object): @trace def __init__(self, *args, **kwargs): print 'MyClass.__init__' @trace def mymethod(self, *args, **kwargs): print 'MyClass.mymethod' foo.info_log("End importing "+__name__) -- Dr. Hellmut Weber m...@hellmutweber.de Degenfeldstraße 2 tel +49-89-3081172 D-80803 München-Schwabing mobil +49-172-8450321 please: No DOCs, no PPTs. why: tinyurl.com/cbgq -- http://mail.python.org/mailman/listinfo/python-list
how to get partition information of a hard disk with python
Hi list, I'm looking for a possibility to access the partiton inforamtion of a hard disk of my computer from within a python program. Googling I found the module 'parted' but didn't see any possibility to get the desired information. Is there any reasonable documentation for the parted module? Any idea is appreciated ;-) TIA Hellmut -- Dr. Hellmut Weber m...@hellmutweber.de Degenfeldstraße 2 tel +49-89-3081172 D-80803 München-Schwabing mobil +49-172-8450321 please: No DOCs, no PPTs. why: tinyurl.com/cbgq -- http://mail.python.org/mailman/listinfo/python-list