Puzzled in the coding of Chinese
Dear list members, I am a newcomer in the world of Python. But I am attracted by Python's power in handling text! Now I apply it to handle Chinese but the Chinese character cann't be displayed on the screen. What displayed on the screen is the 16bits codes. I am so puzzled! I believe this is an easy question to most of python users and an important question to me. Thanks a lot to your help! -- http://mail.python.org/mailman/listinfo/python-list
PIP message: Fatal error in launcher: Unable to create process using '"'
I am getting the message: Fatal error in launcher: Unable to create process using '"' for all pip commands. I tried uninstalling and installing different versions of python, but the pip is still not work, getting the same error message. Has anyone encountered this? Any ideas? Thanks. -- https://mail.python.org/mailman/listinfo/python-list
PIP message: Fatal error in launcher: Unable to create process using '"'
I am getting the message: Fatal error in launcher: Unable to create process using '"' for all pip commands. I tried uninstalling and installing different versions of python, but the pip is still not work, getting the same error message. Has anyone encountered this? Any ideas? Thanks. -- https://mail.python.org/mailman/listinfo/python-list
Re: PIP message: Fatal error in launcher: Unable to create process using '"'
Thanks for the info. "python -m pip " works. Python Path: C:\Users\harriett.xing-adm\AppData\Local\Programs\Python\Python36 C:\Users\harriett.xing-adm\Documents\Learning\python>python Python 3.6.1 (v3.6.1:69c0db5, Mar 21 2017, 18:41:36) [MSC v.1900 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import pip; >>> print(pip.__file__); C:\Users\harriett.xing-adm\AppData\Local\Programs\Python\Python36\lib\site-packages\pip\__init__.py >>> C:\Users\harriett.xing-adm>python --version Python 3.6.1 pip is getting the error regardless of which directory I run it. Thank you for your help. On Thu, Jan 11, 2018 at 10:01 AM, Paul Moore wrote: > Have you done any research (google, for example) and tried any of the > suggested solutions on the web? > > From a quick search, I'd suggest: > > 1. Can you confirm if "python -m pip " > has the same error? > 2. What is the exact path of the pip executable you're running, and if > you go into the Python prompt and do "import pip; print(pip.__file__)" > what is the result? > > It sounds like you have some sort of incorrectly set up environment > with your pip executable being somehow inconsistent with your Python > environment. > > Please confirm the *precise* versions of Python and pip you're > (currently) using which give the error. Also, please confirm that you > get the same errors if you're in a different (empty) directory - > sometimes what's in the current directory can mess things up. > > Paul > > > On 11 January 2018 at 14:39, Harriett Xing > wrote: > > I am getting the message: > > > > Fatal error in launcher: Unable to create process using '"' > > > > for all pip commands. > > > > I tried uninstalling and installing different versions of python, but > the pip is still not work, getting the same error message. > > > > Has anyone encountered this? Any ideas? Thanks. > > -- > > https://mail.python.org/mailman/listinfo/python-list > -- https://mail.python.org/mailman/listinfo/python-list
Re: PIP message: Fatal error in launcher: Unable to create process using '"'
Thanks for the info. I found two copies of pip.exe. One of them was left from a previous installation. Removed the extra copy. Now pip is working. Thank you very much for your help. On Thu, Jan 11, 2018 at 10:46 AM, Harriett Xing wrote: > Thanks for the info. > > "python -m pip " works. > > Python Path: C:\Users\harriett.xing-adm\AppData\Local\Programs\ > Python\Python36 > > C:\Users\harriett.xing-adm\Documents\Learning\python>python > Python 3.6.1 (v3.6.1:69c0db5, Mar 21 2017, 18:41:36) [MSC v.1900 64 bit > (AMD64)] on win32 > Type "help", "copyright", "credits" or "license" for more information. > >>> import pip; > >>> print(pip.__file__); > C:\Users\harriett.xing-adm\AppData\Local\Programs\Python\ > Python36\lib\site-packages\pip\__init__.py > >>> > > > C:\Users\harriett.xing-adm>python --version > Python 3.6.1 > > pip is getting the error regardless of which directory I run it. > > Thank you for your help. > > > > On Thu, Jan 11, 2018 at 10:01 AM, Paul Moore wrote: > >> Have you done any research (google, for example) and tried any of the >> suggested solutions on the web? >> >> From a quick search, I'd suggest: >> >> 1. Can you confirm if "python -m pip " >> has the same error? >> 2. What is the exact path of the pip executable you're running, and if >> you go into the Python prompt and do "import pip; print(pip.__file__)" >> what is the result? >> >> It sounds like you have some sort of incorrectly set up environment >> with your pip executable being somehow inconsistent with your Python >> environment. >> >> Please confirm the *precise* versions of Python and pip you're >> (currently) using which give the error. Also, please confirm that you >> get the same errors if you're in a different (empty) directory - >> sometimes what's in the current directory can mess things up. >> >> Paul >> >> >> On 11 January 2018 at 14:39, Harriett Xing >> wrote: >> > I am getting the message: >> > >> > Fatal error in launcher: Unable to create process using '"' >> > >> > for all pip commands. >> > >> > I tried uninstalling and installing different versions of python, but >> the pip is still not work, getting the same error message. >> > >> > Has anyone encountered this? Any ideas? Thanks. >> > -- >> > https://mail.python.org/mailman/listinfo/python-list >> > > -- https://mail.python.org/mailman/listinfo/python-list
Create Logging module
Hi, I am learning to create python logging. My goal is to create a logging module where I can use as decorator in my main app following is the logging code start here--- import logging #DEBUG: Detailed information, typically of interest only when diagnosing problems. #INFO : Confirmation that things are working as expected. #WARNING (default): An indication that something unexpected happened, or indicative of some problem in the near future # (e.g. 'disk space low'). The software is still working as expected. #ERROR: Due to a more serious problem, the software has not been able to perform some function. #CRITICAL :A serious error, indicating that the program itself may be unable to continue running. from functools import wraps def logme(func_to_log): import logging #Without getLogger name it will log all in root logger = logging.getLogger(__name__) #Check log level within understanable parameter, set to INFO if is not permitable value def check_log_level(logleveltocheck): if any(logleveltocheck.upper() in lf for lf in ['DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL']): return logleveltocheck.upper() else: return 'INFO' log_file_level='INFO' #check_log_level('info') log_console_level='INFO' #check_log_level('info') #root level logger.setLevel('INFO') formatter = logging.Formatter('%(asctime)s :: %(name)s :: %(levelname)s :: %(message)s') #Read log file from parameter logfile='mylogfile.log' file_handler = logging.FileHandler(logfile) file_handler.setLevel(log_file_level) file_handler.setFormatter(formatter) stream_handler = logging.StreamHandler() stream_handler.setLevel(log_console_level) stream_handler.setFormatter(formatter) logger.addHandler() logger.addHandler(stream_handler) #this wraps is to make sure we are returning func_to_log instead of wrapper @wraps(func_to_log) def wrapper(*args, **kwargs): logger.info('Ran with args: {}, and kwargs: {}'.format(args, kwargs)) return func_to_log(*args, **kwargs) return wrapper def timer(func_to_log): import time #this wraps is to make sure we are returning func_to_log instead of wrapper @wraps(func_to_log) def wrapper(*args, **kwargs): t1 = time.time() result = func_to_log(*args, **kwargs) t2 = time.time() - t1 print('{} ran in {} sec'.format(func_to_log.__name__, t2)) return result --- end here--- following is my main app -- start here-- from loggingme import logme def say_hello(name, age): print('Hello {}, I am {}'.format(name, age)) #say_hello=logme(say_hello('Sinardy')) @logme say_hello('Tonny', 8) --- end here--- I have error look like in the wrapper. Can someone point to me where is the issue or is this the correct way to create logging module? PS: above code with python 3.7.4 Thank you. regards, C -- https://mail.python.org/mailman/listinfo/python-list
Re: Create Logging module
Sorry for spamming this is suppose send to tutor-ow...@python.org On Thu, Aug 1, 2019 at 5:08 PM Sinardy Xing wrote: > Hi, > > I am learning to create python logging. > > My goal is to create a logging module where I can use as decorator in my > main app > > following is the logging code > > start here--- > > import logging > > #DEBUG: Detailed information, typically of interest only when > diagnosing problems. > #INFO : Confirmation that things are working as expected. > #WARNING (default): An indication that something unexpected happened, or > indicative of some problem in the near future > # (e.g. 'disk space low'). The software is still working as > expected. > #ERROR: Due to a more serious problem, the software has not been able > to perform some function. > #CRITICAL :A serious error, indicating that the program itself may be > unable to continue running. > > from functools import wraps > > def logme(func_to_log): > import logging > > #Without getLogger name it will log all in root > logger = logging.getLogger(__name__) > > #Check log level within understanable parameter, set to INFO if is not > permitable value > def check_log_level(logleveltocheck): > if any(logleveltocheck.upper() in lf for lf in ['DEBUG', > 'INFO', 'WARNING', 'ERROR', 'CRITICAL']): > return logleveltocheck.upper() > else: > return 'INFO' > > log_file_level='INFO' #check_log_level('info') > log_console_level='INFO' #check_log_level('info') > > #root level > logger.setLevel('INFO') > > formatter = logging.Formatter('%(asctime)s :: %(name)s :: > %(levelname)s :: %(message)s') > > #Read log file from parameter > logfile='mylogfile.log' > file_handler = logging.FileHandler(logfile) > file_handler.setLevel(log_file_level) > file_handler.setFormatter(formatter) > > stream_handler = logging.StreamHandler() > stream_handler.setLevel(log_console_level) > stream_handler.setFormatter(formatter) > > logger.addHandler() > logger.addHandler(stream_handler) > > #this wraps is to make sure we are returning func_to_log instead of > wrapper > @wraps(func_to_log) > def wrapper(*args, **kwargs): > logger.info('Ran with args: {}, and kwargs: {}'.format(args, > kwargs)) > return func_to_log(*args, **kwargs) > > return wrapper > > > def timer(func_to_log): > import time > > #this wraps is to make sure we are returning func_to_log instead of > wrapper > @wraps(func_to_log) > def wrapper(*args, **kwargs): > t1 = time.time() > result = func_to_log(*args, **kwargs) > t2 = time.time() - t1 > print('{} ran in {} sec'.format(func_to_log.__name__, t2)) > return result > > --- end here--- > > > following is my main app > > -- start here-- > from loggingme import logme > > def say_hello(name, age): > print('Hello {}, I am {}'.format(name, age)) > > #say_hello=logme(say_hello('Sinardy')) > @logme > say_hello('Tonny', 8) > > --- end here--- > > > I have error look like in the wrapper. > > Can someone point to me where is the issue or is this the correct way to > create logging module? > > PS: above code with python 3.7.4 > > Thank you. > > regards, > C > -- https://mail.python.org/mailman/listinfo/python-list
reading specific lines of a file
Hi All, I want to read specific lines of a huge txt file (I know the line #). Each line might have different sizes. Is there a convenient and fast way of doing this in Python? Thanks. Yi Xing -- http://mail.python.org/mailman/listinfo/python-list
building an index for large text files for fast access
Hi, I need to read specific lines of huge text files. Each time, I know exactly which line(s) I want to read. readlines() or readline() in a loop is just too slow. Since different lines have different size, I cannot use seek(). So I am thinking of building an index for the file for fast access. Can anybody give me some tips on how to do this in Python? Thanks. Yi -- http://mail.python.org/mailman/listinfo/python-list
Memory problem
Hi, I need to read a large amount of data into a list. So I am trying to see if I'll have any memory problem. When I do x=range(2700*2700*3) I got the following message: Traceback (most recent call last): File "", line 1, in ? MemoryError Any way to get around this problem? I have a machine of 4G memory. The total number of data points (float) that I need to read is in the order of 200-300 millions. Thanks. -- http://mail.python.org/mailman/listinfo/python-list
Memory problem
I tried the following code: >>> i=0 >>> n=2600*2600*30 >>> a=array.array("f") >>> while (i<=n): .. i=i+1 .. a.append(float(i)) .. Traceback (most recent call last): File "", line 3, in ? MemoryError to see the size of the array at the time of memory error: >>>len(a) 8539248. I use Windows XP x64 with 4GB RAM. -- http://mail.python.org/mailman/listinfo/python-list
Re: Memory problem
On a related question: how do I initialize a list or an array with a pre-specified number of elements, something like int p[100] in C? I can do append() for 100 times but this looks silly... Thanks. Yi Xing -- http://mail.python.org/mailman/listinfo/python-list
Re: Memory problem
Thanks! I just found that that I have no problem with x=[[10.0]*2560*2560]*500, but x=range(1*2560*2560*30) doesn't work. -Yi On Aug 14, 2006, at 3:08 PM, Larry Bates wrote: > Yi Xing wrote: >> On a related question: how do I initialize a list or an array with a >> pre-specified number of elements, something like >> int p[100] in C? I can do append() for 100 times but this looks >> silly... >> >> Thanks. >> >> Yi Xing >> > Unlike other languages this is seldom done in Python. I think you > should > probably be looking at http://numeric.scipy.org/ if you want to have > "traditional" arrays of floats. > > -Larry > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://mail.python.org/mailman/listinfo/python-list
Re: Memory problem
Is there a way that I can define a two-dimensional array in array.array()? Thanks. On Aug 14, 2006, at 2:28 PM, John Machin wrote: > Yi Xing wrote: >> I tried the following code: >> >>>>> i=0 >>>>> n=2600*2600*30 >>>>> a=array.array("f") >>>>> while (i<=n): >> .. i=i+1 >> .. a.append(float(i)) > > Not a good idea. The array has to be resized, which may mean that a > realloc won't work because of fragmentation, you're out of luck because > plan B is to malloc another chunk, but that's likely to fail as well. >> .. >> Traceback (most recent call last): >> File "", line 3, in ? >> MemoryError >> >> to see the size of the array at the time of memory error: >>>>> len(a) >> 8539248. > > Incredible. That's only 34 MB. What is the size of your paging file? > What memory guzzlers were you running at the same time? What was the > Task Manager "Performance" pane showing while your test was running? > What version of Python? > > FWIW I got up to len(a) == 122998164 (that's 14 times what you got) on > a machine with only 1GB of memory and a 1523MB paging file, with > Firefox & ZoneAlarm running (the pagefile was showing approx 300MB in > use at the start of the test). > >> I use Windows XP x64 with 4GB RAM. > > Maybe there's a memory allocation problem with the 64-bit version. > Maybe MS just dropped in the old Win95 memory allocator that the timbot > used to fulminate about :-( > > Cheers, > John > > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://mail.python.org/mailman/listinfo/python-list
Re: Memory problem
I used the array module and loaded all the data into an array. Everything works fine now. On Aug 14, 2006, at 4:01 PM, John Machin wrote: > Yi Xing wrote: >> Thanks! I just found that that I have no problem with >> x=[[10.0]*2560*2560]*500, but x=range(1*2560*2560*30) doesn't work. >> > > range(1*2560*2560*30) is creating a list of 196M *unique* ints. > Assuming 32-bit ints and pointers: that's 4 bytes each for the value, 4 > for the type pointer, 4 for the refcount and 4 for the actual list > element (a pointer to the 12-byte object). so that's one chunk of > 4x196M = 786MB of contiguous list, plus 196M chunks each whatever size > gets allocated for a request of 12 bytes. Let's guess at 16. So the > total memory you need is 3920M. > > Now let's look at [[10.0]*2560*2560]*500. > Firstly that creates a tiny list [10.0]. then you create a list that > contains 2560*2560 = 6.5 M references to that *one* object containing > 10.0. That's 26MB. Then you make a list of 500 references to that big > list. This new list costs you 2000 bytes. Total required: about 26.2MB. > The minute you start having non-unique numbers instead of 10.0, this > all falls apart. > > In any case, your above comparison is nothing at all to do with the > solution that you need, which as already explained will involve > array.array or numpy. > > What you now need to do is answer the questions about your pagefile > etc. > > Cheers, > John > > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://mail.python.org/mailman/listinfo/python-list
MySQLdb installation error
Hi, I met the following error when I tried to install MySQLdb. I had no problem installing numarray, Numeric, Rpy, etc. Does anyone know what's the problem? Thanks! running install running build running build_py creating build creating build/lib.darwin-7.9.0-Power_Macintosh-2.4 copying _mysql_exceptions.py -> build/lib.darwin-7.9.0-Power_Macintosh-2.4 creating build/lib.darwin-7.9.0-Power_Macintosh-2.4/MySQLdb copying MySQLdb/__init__.py -> build/lib.darwin-7.9.0-Power_Macintosh-2.4/MySQLdb copying MySQLdb/converters.py -> build/lib.darwin-7.9.0-Power_Macintosh-2.4/MySQLdb copying MySQLdb/connections.py -> build/lib.darwin-7.9.0-Power_Macintosh-2.4/MySQLdb copying MySQLdb/cursors.py -> build/lib.darwin-7.9.0-Power_Macintosh-2.4/MySQLdb copying MySQLdb/release.py -> build/lib.darwin-7.9.0-Power_Macintosh-2.4/MySQLdb copying MySQLdb/times.py -> build/lib.darwin-7.9.0-Power_Macintosh-2.4/MySQLdb creating build/lib.darwin-7.9.0-Power_Macintosh-2.4/MySQLdb/constants copying MySQLdb/constants/__init__.py -> build/lib.darwin-7.9.0-Power_Macintosh-2.4/MySQLdb/constants copying MySQLdb/constants/CR.py -> build/lib.darwin-7.9.0-Power_Macintosh-2.4/MySQLdb/constants copying MySQLdb/constants/FIELD_TYPE.py -> build/lib.darwin-7.9.0-Power_Macintosh-2.4/MySQLdb/constants copying MySQLdb/constants/ER.py -> build/lib.darwin-7.9.0-Power_Macintosh-2.4/MySQLdb/constants copying MySQLdb/constants/FLAG.py -> build/lib.darwin-7.9.0-Power_Macintosh-2.4/MySQLdb/constants copying MySQLdb/constants/REFRESH.py -> build/lib.darwin-7.9.0-Power_Macintosh-2.4/MySQLdb/constants copying MySQLdb/constants/CLIENT.py -> build/lib.darwin-7.9.0-Power_Macintosh-2.4/MySQLdb/constants running build_ext building '_mysql' extension creating build/temp.darwin-7.9.0-Power_Macintosh-2.4 gcc -fno-strict-aliasing -Wno-long-double -no-cpp-precomp -mno-fused-madd -fno-common -dynamic -DNDEBUG -g -O3 -Wall -Wstrict-prototypes -I/usr/include/mysql -I/Library/Frameworks/Python.framework/Versions/2.4/include/python2.4 -c _mysql.c -o build/temp.darwin-7.9.0-Power_Macintosh-2.4/_mysql.o -fno-omit-frame-pointer -arch i386 -arch ppc -pipe -Dversion_info="(1,2,1,'final',2)" -D__version__="1.2.1_p2" gcc: cannot read specs file for arch `i386' error: command 'gcc' failed with exit status 1 -- http://mail.python.org/mailman/listinfo/python-list
MySQLdb installation error
I log into the machine remotely. How do I check the Mac OSX version number under command line? Thanks. hiaips rosedb0 at gmail.com Wed Aug 16 01:23:10 CEST 2006 * Previous message: MySQLdb installation error * Next message: What would be the best way to run python client in the background * Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] Yi Xing wrote: > Hi, > > I met the following error when I tried to install MySQLdb. I had no > problem installing numarray, Numeric, Rpy, etc. Does anyone know > what's the problem? Thanks! > > running install > running build > running build_py > creating build > creating build/lib.darwin-7.9.0-Power_Macintosh-2.4 > copying _mysql_exceptions.py -> > build/lib.darwin-7.9.0-Power_Macintosh-2.4 > creating build/lib.darwin-7.9.0-Power_Macintosh-2.4/MySQLdb > copying MySQLdb/__init__.py -> > build/lib.darwin-7.9.0-Power_Macintosh-2.4/MySQLdb > copying MySQLdb/converters.py -> > build/lib.darwin-7.9.0-Power_Macintosh-2.4/MySQLdb > copying MySQLdb/connections.py -> > build/lib.darwin-7.9.0-Power_Macintosh-2.4/MySQLdb > copying MySQLdb/cursors.py -> > build/lib.darwin-7.9.0-Power_Macintosh-2.4/MySQLdb > copying MySQLdb/release.py -> > build/lib.darwin-7.9.0-Power_Macintosh-2.4/MySQLdb > copying MySQLdb/times.py -> > build/lib.darwin-7.9.0-Power_Macintosh-2.4/MySQLdb > creating build/lib.darwin-7.9.0-Power_Macintosh-2.4/MySQLdb/constants > copying MySQLdb/constants/__init__.py -> > build/lib.darwin-7.9.0-Power_Macintosh-2.4/MySQLdb/constants > copying MySQLdb/constants/CR.py -> > build/lib.darwin-7.9.0-Power_Macintosh-2.4/MySQLdb/constants > copying MySQLdb/constants/FIELD_TYPE.py -> > build/lib.darwin-7.9.0-Power_Macintosh-2.4/MySQLdb/constants > copying MySQLdb/constants/ER.py -> > build/lib.darwin-7.9.0-Power_Macintosh-2.4/MySQLdb/constants > copying MySQLdb/constants/FLAG.py -> > build/lib.darwin-7.9.0-Power_Macintosh-2.4/MySQLdb/constants > copying MySQLdb/constants/REFRESH.py -> > build/lib.darwin-7.9.0-Power_Macintosh-2.4/MySQLdb/constants > copying MySQLdb/constants/CLIENT.py -> > build/lib.darwin-7.9.0-Power_Macintosh-2.4/MySQLdb/constants > running build_ext > building '_mysql' extension > creating build/temp.darwin-7.9.0-Power_Macintosh-2.4 > gcc -fno-strict-aliasing -Wno-long-double -no-cpp-precomp > -mno-fused-madd -fno-common -dynamic -DNDEBUG -g -O3 -Wall > -Wstrict-prototypes -I/usr/include/mysql > -I/Library/Frameworks/Python.framework/Versions/2.4/include/python2.4 > -c _mysql.c -o build/temp.darwin-7.9.0-Power_Macintosh-2.4/_mysql.o > -fno-omit-frame-pointer -arch i386 -arch ppc -pipe > -Dversion_info="(1,2,1,'final',2)" -D__version__="1.2.1_p2" > gcc: cannot read specs file for arch `i386' > error: command 'gcc' failed with exit status 1 What version of OSX are you running? -- http://mail.python.org/mailman/listinfo/python-list