Re: The use of type()

2019-02-10 Thread ^Bart
a = 5 print(a.__class__.__name__) int b = 5.0 print(b.__class__.__name__) float Thank you very much! :) ^Bart -- https://mail.python.org/mailman/listinfo/python-list

RE: The use of type()

2019-02-10 Thread Avi Gross
then within that for the name like this: >>> a = 5 >>> print(a.__class__.__name__) int >>> b = 5.0 >>> print(b.__class__.__name__) float -Original Message- From: Python-list On Behalf Of Avi Gross Sent: Sunday, February 10, 2019 5:43 PM To: python-lis

RE: The use of type()

2019-02-10 Thread Avi Gross
ist: >>> a = ["list", "of", "anything"] ... >>> print(text[first : second]) list Of course this is so simple it must be out there in some module. -Original Message- From: Python-list On Behalf Of ^Bart Sent: Sunday, February 10, 2019 4:43 PM

Re: The use of type()

2019-02-10 Thread Chris Angelico
On Mon, Feb 11, 2019 at 8:46 AM ^Bart wrote: > > I need to print something like "this variable is int" or "this variable > is string" > > n1 = 10 > n2 = 23 > > print ("Total of n1+n2 is: ",n1+n2," the type is", type(n1+n2)) > > When I run it I have: > > Total of n1+n2 is: 33 the type is > >>>

The use of type()

2019-02-10 Thread ^Bart
I need to print something like "this variable is int" or "this variable is string" n1 = 10 n2 = 23 print ("Total of n1+n2 is: ",n1+n2," the type is", type(n1+n2)) When I run it I have: Total of n1+n2 is: 33 the type is >>> I'd like to read "the type is int" and NOT "the type is , how cou

Re: Why is the use of an undefined name not a syntax error?

2018-04-01 Thread Terry Reedy
On 4/1/2018 5:24 PM, David Foster wrote: My understanding is that the Python interpreter already has enough information when bytecode-compiling a .py file to determine which names correspond to local variables in functions. That suggests it has enough information to identify all valid names in

Re: Why is the use of an undefined name not a syntax error?

2018-04-01 Thread Steven D'Aprano
On Sun, 01 Apr 2018 14:24:38 -0700, David Foster wrote: > My understanding is that the Python interpreter already has enough > information when bytecode-compiling a .py file to determine which names > correspond to local variables in functions. That suggests it has enough > information to identify

Re: Why is the use of an undefined name not a syntax error?

2018-04-01 Thread Ben Bacarisse
David Foster writes: > My understanding is that the Python interpreter already has enough > information when bytecode-compiling a .py file to determine which > names correspond to local variables in functions. That suggests it has > enough information to identify all valid names in a .py file and

Re: Why is the use of an undefined name not a syntax error?

2018-04-01 Thread Chris Angelico
On Mon, Apr 2, 2018 at 8:05 AM, Devin Jeanpierre wrote: > On Sun, Apr 1, 2018 at 2:38 PM, Chris Angelico wrote: >> On Mon, Apr 2, 2018 at 7:24 AM, David Foster wrote: >>> My understanding is that the Python interpreter already has enough >>> information when bytecode-compiling a .py file to det

Re: Why is the use of an undefined name not a syntax error?

2018-04-01 Thread Devin Jeanpierre
On Sun, Apr 1, 2018 at 2:38 PM, Chris Angelico wrote: > On Mon, Apr 2, 2018 at 7:24 AM, David Foster wrote: >> My understanding is that the Python interpreter already has enough >> information when bytecode-compiling a .py file to determine which names >> correspond to local variables in functi

Re: Why is the use of an undefined name not a syntax error?

2018-04-01 Thread Devin Jeanpierre
> But if it is cheap to detect a wide variety of name errors at compile time, > is there any particular reason it is not done? >From my perspective, it is done, but by tools that give better output than Python's parser. :) Linters (like pylint) are better than syntax errors here, because they co

Re: Why is the use of an undefined name not a syntax error?

2018-04-01 Thread Chris Angelico
On Mon, Apr 2, 2018 at 7:24 AM, David Foster wrote: > My understanding is that the Python interpreter already has enough > information when bytecode-compiling a .py file to determine which names > correspond to local variables in functions. That suggests it has enough > information to identify

Why is the use of an undefined name not a syntax error?

2018-04-01 Thread David Foster
My understanding is that the Python interpreter already has enough information when bytecode-compiling a .py file to determine which names correspond to local variables in functions. That suggests it has enough information to identify all valid names in a .py file and in particular to identify w

How to search out all Zip codes and replace with the first 2 digits, in a Pandas dataframe, with the use of regex?

2017-03-20 Thread David Shi via Python-list
Hi, there, Can anyone help? How to search out all Zip codes and replace with the first 2 digits, in a Pandas dataframe, with the use of regex? For instance, a ZIP code 33132 was found and replaced with 33. Looking forward to hearing from you. Regards. David -- https://mail.python.org/mailman

The use of sys.exc_info for catching exceptions

2017-02-01 Thread Tiago M. Vieira
Hi, I've came to a problem where I want to keep backwards and forwards compatibility with an exception syntax. And I mean by backwards going further down to Python 2.5. I was pointed to this option from a stack overflow answer[1] that works forward and backwards, I rewrite the solution here: imp

Re: Fwd: Fwd: Python freeze fails with warning: the use of `tempnam' is dangerous, better use `mkstemp'

2016-09-08 Thread dieter
"Alexander N. Moibenko" writes: > In fact I tried issuing commands manually, but they did not give me > any hint more than I already had. When I remember right, then "gcc" has an option to show details about the calling of the phase commands ("gcc" is a coordinating programm delegating the real w

Re: Fwd: Fwd: Python freeze fails with warning: the use of `tempnam' is dangerous, better use `mkstemp'

2016-09-08 Thread Alexander N. Moibenko
On 09/08/2016 12:19 PM, Chris Angelico wrote: On Fri, Sep 9, 2016 at 2:50 AM, Alexander N. Moibenko wrote: The output is long so, I am replying to you only: Not too long, fortunately. Replying back to the list with a trimmed version. make[1]: Entering directory `/opt/enstore/src/ENCPBIN_TE

Re: Fwd: Fwd: Python freeze fails with warning: the use of `tempnam' is dangerous, better use `mkstemp'

2016-09-08 Thread Chris Angelico
On Fri, Sep 9, 2016 at 2:50 AM, Alexander N. Moibenko wrote: > The output is long so, I am replying to you only: Not too long, fortunately. Replying back to the list with a trimmed version. > make[1]: Entering directory `/opt/enstore/src/ENCPBIN_TEMP' (Curious path name.) > /opt/enstore/Python

Re: Fwd: Fwd: Python freeze fails with warning: the use of `tempnam' is dangerous, better use `mkstemp'

2016-09-08 Thread Chris Angelico
On Fri, Sep 9, 2016 at 1:12 AM, Alexander N. Moibenko wrote: > Yes this Linux Red Hat 6. > > [enstore@dmsen02 enstore-log]$ cat /etc/redhat-release > Scientific Linux Fermi release 6.5 (Ramsey) > Please note that the same set of modules buils with python 2.6.3 and fails > with python 2.7 ( I m

Re: Fwd: Fwd: Python freeze fails with warning: the use of `tempnam' is dangerous, better use `mkstemp'

2016-09-08 Thread Alexander N. Moibenko
On 09/08/2016 11:06 AM, Rustom Mody wrote: On Thursday, September 8, 2016 at 8:57:23 PM UTC+5:30, Alexander N. Moibenko wrote: Yes this Linux Red Hat 6. [enstore@dmsen02 enstore-log]$ cat /etc/redhat-release Scientific Linux Fermi release 6.5 (Ramsey) Please note that the same set of modules

Re: Fwd: Fwd: Python freeze fails with warning: the use of `tempnam' is dangerous, better use `mkstemp'

2016-09-08 Thread Rustom Mody
On Thursday, September 8, 2016 at 8:57:23 PM UTC+5:30, Alexander N. Moibenko wrote: > Yes this Linux Red Hat 6. > > [enstore@dmsen02 enstore-log]$ cat /etc/redhat-release > Scientific Linux Fermi release 6.5 (Ramsey) > Please note that the same set of modules buils with python 2.6.3 and > fails

Re: Fwd: Fwd: Python freeze fails with warning: the use of `tempnam' is dangerous, better use `mkstemp'

2016-09-08 Thread Alexander N. Moibenko
Yes this Linux Red Hat 6. [enstore@dmsen02 enstore-log]$ cat /etc/redhat-release Scientific Linux Fermi release 6.5 (Ramsey) Please note that the same set of modules buils with python 2.6.3 and fails with python 2.7 ( I mean any pyhon 2.7 release). On 09/08/2016 09:51 AM, Chris Angelico w

Re: Fwd: Fwd: Python freeze fails with warning: the use of `tempnam' is dangerous, better use `mkstemp'

2016-09-08 Thread Chris Angelico
On Fri, Sep 9, 2016 at 12:48 AM, Alexander N. Moibenko wrote: > In fact I tried issuing commands manually, but they did not give me any hint > more than I already had. > > In python 2.6 this all works with the same libc, of course (because I tried > to compile on the same machine). > Can you prov

Re: Fwd: Fwd: Python freeze fails with warning: the use of `tempnam' is dangerous, better use `mkstemp'

2016-09-08 Thread Alexander N. Moibenko
benko" writes: when I build a binary with python 2.6 it builds without any problem. When I build with python 2.7 the build fails after warnings like: /opt/python/Python-2.7.12/Modules/posixmodule.o: In function `posix_tempnam': /opt/python/Python-2.7.12/./Modules/posixmodule.c:7578: warn

Re: Fwd: Fwd: Python freeze fails with warning: the use of `tempnam' is dangerous, better use `mkstemp'

2016-09-08 Thread Alexander N. Moibenko
Finney wrote: "Alexander N. Moibenko" writes: /opt/python/Python-2.7.12/./Modules/posixmodule.c:7578: warning: the use of `tempnam' is dangerous, better use `mkstemp' collect2: ld returned 1 exit status How this can be fixed? The clearest answer is already there in the warn

Re: Fwd: Fwd: Python freeze fails with warning: the use of `tempnam' is dangerous, better use `mkstemp'

2016-09-07 Thread dieter
python/Python-2.7.12/./Modules/posixmodule.c:7578: warning: the > use of `tempnam' is dangerous, better use `mkstemp' > collect2: ld returned 1 exit status > > How this can be fixed? I doubt that the (compiler) warning is responsible for the (linker) failure. When I am faced with p

Re: Fwd: Fwd: Python freeze fails with warning: the use of `tempnam' is dangerous, better use `mkstemp'

2016-09-07 Thread Ben Finney
"Alexander N. Moibenko" writes: > /opt/python/Python-2.7.12/./Modules/posixmodule.c:7578: warning: the > use of `tempnam' is dangerous, better use `mkstemp' > collect2: ld returned 1 exit status > > How this can be fixed? The clearest answer is already there i

Fwd: Fwd: Python freeze fails with warning: the use of `tempnam' is dangerous, better use `mkstemp'

2016-09-07 Thread Alexander N. Moibenko
Hello, when I build a binary with python 2.6 it builds without any problem. When I build with python 2.7 the build fails after warnings like: /opt/python/Python-2.7.12/Modules/posixmodule.o: In function `posix_tempnam': /opt/python/Python-2.7.12/./Modules/posixmodule.c:7578: warning: the us

Reference counting and the use of PYTHONDUMPREFS

2014-01-18 Thread Anders Wegge Keller
During the final test of a bit of embedded python, I wanted to see if I had any hanging references. To my suprise, I ended up with a rather large amount, after running combinerefs.py. And even with the simplest[1] possible use of embedding, I end up with 13475 still-living references. If this i

Re: accessing an OLE Automation (IDispatch) server from python which requires the use of "out params"

2012-12-11 Thread Mark Hammond
On 12/12/2012 2:48 AM, bitbucket wrote: On Monday, December 10, 2012 8:16:43 PM UTC-5, Mark Hammond wrote: "out" params are best supported if the object supplied a typelib - then Python knows the params are out and does the right thing automagically. If out params are detected, the result of the

Re: accessing an OLE Automation (IDispatch) server from python which requires the use of "out params"

2012-12-11 Thread bitbucket
On Tuesday, December 11, 2012 10:48:53 AM UTC-5, bitbucket wrote: > > I noticed that the argument type is different for the out param (16392 > instead of 8). However, it doesn't appear to me that its generating return > values instead of args (though I'm not very experienced in python). > I see

Re: accessing an OLE Automation (IDispatch) server from python which requires the use of "out params"

2012-12-11 Thread bitbucket
On Monday, December 10, 2012 8:16:43 PM UTC-5, Mark Hammond wrote: > "out" params are best supported if the object supplied a typelib - then > Python knows the params are out and does the right thing automagically. > If out params are detected, the result of the function will be a tuple > of (

Re: accessing an OLE Automation (IDispatch) server from python which requires the use of "out params"

2012-12-11 Thread bitbucket
On Tuesday, December 11, 2012 3:42:35 AM UTC-5, Paul Kölle wrote: > Before switching technologies I'd check if this solves your problem > > http://geekswithblogs.net/Lance/archive/2009/01/14/pass-by-reference-parameters-in-powershell.aspx > > > TL;DR IMHO "out" parameters are basically pointer

Re: accessing an OLE Automation (IDispatch) server from python which requires the use of "out params"

2012-12-11 Thread Paul Kölle
Hi, Am 10.12.2012 20:13, schrieb bitbucket: I have an existing Windows application which provides an OLE Automation (IDispatch) interface. I'm not able to change that interface. I'd like to call it from a scripting language. I figure this would provide a nice quick way to invoke on the app.

Re: accessing an OLE Automation (IDispatch) server from python which requires the use of "out params"

2012-12-10 Thread Mark Hammond
On 11/12/2012 8:39 AM, bitbucket wrote: On Monday, December 10, 2012 3:58:33 PM UTC-5, Terry Reedy wrote: I believe the easiest way to do that is to install the pywin extensions http://sourceforge.net/projects/pywin32/?source=directory I assume it can handle out params. That definitely looks

Re: accessing an OLE Automation (IDispatch) server from python which requires the use of "out params"

2012-12-10 Thread bitbucket
On Monday, December 10, 2012 3:58:33 PM UTC-5, Terry Reedy wrote: > I believe the easiest way to do that is to install the pywin extensions > > http://sourceforge.net/projects/pywin32/?source=directory > > I assume it can handle out params. That definitely looks like a good starting point. Just

Re: accessing an OLE Automation (IDispatch) server from python which requires the use of "out params"

2012-12-10 Thread Terry Reedy
On 12/10/2012 2:13 PM, bitbucket wrote: I have an existing Windows application which provides an OLE Automation (IDispatch) interface. I'm not able to change that interface. I'd like to call it from a scripting language. I figure this would provide a nice quick way to invoke on the app. I be

accessing an OLE Automation (IDispatch) server from python which requires the use of "out params"

2012-12-10 Thread bitbucket
I have an existing Windows application which provides an OLE Automation (IDispatch) interface. I'm not able to change that interface. I'd like to call it from a scripting language. I figure this would provide a nice quick way to invoke on the app. I initially tried this with Windows Powershe

What is the use of python.cache_ubuntu?

2012-05-03 Thread Fayaz Yusuf Khan
My Ubuntu 11.04 server ran out of inodes due to too many files in '/tmp/python.cache_ubuntu'. Does anyone know what it does? -- Cloud architect and hacker, Dexetra, India fayaz.yusuf.khan_AT_gmail_DOT_com fayaz_AT_dexetra_DOT_com +91-9746-830-823 -- http://mail.python.org/mailman/listinfo/python

Re: Questions about the use of descriptors.

2012-03-15 Thread Ian Kelly
On Thu, Mar 15, 2012 at 11:32 AM, Steven W. Orr wrote: > Question 1: > > I have a class A with one attribute and I define __get__ and __set__ for > that class. Then I create another class B that uses it. > > Why does B require that the instance of A be a class variable in B and not > created as an

Questions about the use of descriptors.

2012-03-15 Thread Steven W. Orr
Question 1: I have a class A with one attribute and I define __get__ and __set__ for that class. Then I create another class B that uses it. Why does B require that the instance of A be a class variable in B and not created as an instance variable in __init__? E.g., # This works fine. class

Re: Enabling the use of POSIX character classes in Python

2010-12-11 Thread Perry Johnson
On 2010-12-11, MRAB wrote: > On 11/12/2010 17:33, Perry Johnson wrote: >> Python's re module does not support POSIX character classes, for >> example [:alpha:]. It is, of course, trivial to simulate them using >> character ranges when the text to be matched uses the ASCII character >> set. Sadly,

Re: Enabling the use of POSIX character classes in Python

2010-12-11 Thread Martin v. Loewis
Am 11.12.2010 18:33, schrieb Perry Johnson: > Python's re module does not support POSIX character classes, for > example [:alpha:]. It is, of course, trivial to simulate them using > character ranges when the text to be matched uses the ASCII character > set. Sadly, my problem is that I need to pro

Re: Enabling the use of POSIX character classes in Python

2010-12-11 Thread MRAB
On 11/12/2010 17:33, Perry Johnson wrote: Python's re module does not support POSIX character classes, for example [:alpha:]. It is, of course, trivial to simulate them using character ranges when the text to be matched uses the ASCII character set. Sadly, my problem is that I need to process Uni

Enabling the use of POSIX character classes in Python

2010-12-11 Thread Perry Johnson
Python's re module does not support POSIX character classes, for example [:alpha:]. It is, of course, trivial to simulate them using character ranges when the text to be matched uses the ASCII character set. Sadly, my problem is that I need to process Unicode text. The re module has its own charact

Re: Replace and inserting strings within .txt files with the use of regex

2010-08-16 Thread Νίκος
On 10 Αύγ, 01:43, MRAB wrote: > Íßêïò wrote: > > D:\>convert.py > >   File "D:\convert.py", line 34 > > SyntaxError: Non-ASCII character '\xce' in file D:\convert.py on line > > 34, but no > >  encoding declared; seehttp://www.python.org/peps/pep-0263.htmlfor > > details > > > D:\> > > > What does

Re: Replace and inserting strings within .txt files with the use of regex

2010-08-11 Thread Νίκος
On 10 Αύγ, 18:12, MRAB wrote: > Νίκος wrote: > > [snip] > > > > > > > The ID number of each php page was contained in the old php code > > within this string > > > PageID = some_number > > > So instead of create a new ID number for eaqch page i have to pull out > > this number to store to the begi

Re: Replace and inserting strings within .txt files with the use of regex

2010-08-10 Thread MRAB
Νίκος wrote: [snip] The ID number of each php page was contained in the old php code within this string PageID = some_number So instead of create a new ID number for eaqch page i have to pull out this number to store to the beginnign to the file as comment line, because it has direct relations

Re: Replace and inserting strings within .txt files with the use of regex

2010-08-10 Thread Νίκος
Please help me with these last changes before i try to perform an overall change. its almost done! -- http://mail.python.org/mailman/listinfo/python-list

Re: Replace and inserting strings within .txt files with the use of regex

2010-08-09 Thread Νίκος
On 10 Αύγ, 01:43, MRAB wrote: > Íßêïò wrote: > > D:\>convert.py > >   File "D:\convert.py", line 34 > > SyntaxError: Non-ASCII character '\xce' in file D:\convert.py on line > > 34, but no > >  encoding declared; seehttp://www.python.org/peps/pep-0263.htmlfor > > details > > > D:\> > > > What does

Re: Replace and inserting strings within .txt files with the use of regex

2010-08-09 Thread MRAB
Νίκος wrote: D:\>convert.py File "D:\convert.py", line 34 SyntaxError: Non-ASCII character '\xce' in file D:\convert.py on line 34, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details D:\> What does it refering too? what character cannot be identified? Line 34

Re: Replace and inserting strings within .txt files with the use of regex

2010-08-09 Thread MRAB
Νίκος wrote: On 9 Αύγ, 23:17, MRAB wrote: Νίκος wrote: On 9 Αύγ, 21:05, Thomas Jollans wrote: On Monday 09 August 2010, it occurred to Νίκος to exclaim: On 9 Αύγ, 19:21, Peter Otten <__pete...@web.de> wrote: Νίκος wrote: Please tell me that no matter what weird charhs has inside ic an sti

Re: Replace and inserting strings within .txt files with the use of regex

2010-08-09 Thread Νίκος
D:\>convert.py File "D:\convert.py", line 34 SyntaxError: Non-ASCII character '\xce' in file D:\convert.py on line 34, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details D:\> What does it refering too? what character cannot be identified? Line 34 is: src_data

Re: Replace and inserting strings within .txt files with the use of regex

2010-08-09 Thread Νίκος
On 9 Αύγ, 23:28, MRAB wrote: > Íßêïò wrote: > > On 9 Áýã, 10:07, Íßêïò wrote: > >> Now the code looks as follows: > > >> = > >> #!/usr/bin/python > > >> import re, os, sys > > >> id = 0  # unique page_id > > >> for currdir, files, dirs in os.walk('test'): > > >>      

Re: Replace and inserting strings within .txt files with the use of regex

2010-08-09 Thread Νίκος
On 9 Αύγ, 23:17, MRAB wrote: > Νίκος wrote: > > On 9 Αύγ, 21:05, Thomas Jollans wrote: > >> On Monday 09 August 2010, it occurred to Νίκος to exclaim: > > >>> On 9 Αύγ, 19:21, Peter Otten <__pete...@web.de> wrote: > Νίκος wrote: > > Please tell me that no matter what weird charhs has ins

Re: Replace and inserting strings within .txt files with the use of regex

2010-08-09 Thread MRAB
Νίκος wrote: On 9 Αύγ, 10:07, Νίκος wrote: Now the code looks as follows: = #!/usr/bin/python import re, os, sys id = 0 # unique page_id for currdir, files, dirs in os.walk('test'): for f in files: if f.endswith('php'): [snip] I jus

Re: Replace and inserting strings within .txt files with the use of regex

2010-08-09 Thread MRAB
Νίκος wrote: On 9 Αύγ, 21:05, Thomas Jollans wrote: On Monday 09 August 2010, it occurred to Νίκος to exclaim: On 9 Αύγ, 19:21, Peter Otten <__pete...@web.de> wrote: Νίκος wrote: Please tell me that no matter what weird charhs has inside ic an still open thosie fiels and make the neccessary

Re: Replace and inserting strings within .txt files with the use of regex

2010-08-09 Thread Νίκος
On 9 Αύγ, 10:07, Νίκος wrote: > Now the code looks as follows: > > = > #!/usr/bin/python > > import re, os, sys > > id = 0  # unique page_id > > for currdir, files, dirs in os.walk('test'): > >         for f in files: > >                 if f.endswith('php'): > >      

Re: Replace and inserting strings within .txt files with the use of regex

2010-08-09 Thread Νίκος
On 9 Αύγ, 21:05, Thomas Jollans wrote: > On Monday 09 August 2010, it occurred to Νίκος to exclaim: > > > > > > > On 9 Αύγ, 19:21, Peter Otten <__pete...@web.de> wrote: > > > Νίκος wrote: > > > > Please tell me that no matter what weird charhs has inside ic an still > > > > open thosie fiels and m

Re: Replace and inserting strings within .txt files with the use of regex

2010-08-09 Thread Νίκος
On 8 Αύγ, 20:29, John S wrote: > When replacing text in an HTML document with re.sub, you want to use > the re.S (singleline) option; otherwise your pattern won't match when > the opening tag is on one line and the closing is on another. Thats exactly the problem iam facing now with this stateme

Re: Replace and inserting strings within .txt files with the use of regex

2010-08-09 Thread Thomas Jollans
On Monday 09 August 2010, it occurred to Νίκος to exclaim: > On 9 Αύγ, 19:21, Peter Otten <__pete...@web.de> wrote: > > Νίκος wrote: > > > Please tell me that no matter what weird charhs has inside ic an still > > > open thosie fiels and make the neccessary replacements. > > > > Go back to 2.6 for

Re: Replace and inserting strings within .txt files with the use of regex

2010-08-09 Thread Νίκος
On 9 Αύγ, 19:21, Peter Otten <__pete...@web.de> wrote: > Νίκος wrote: > > Please tell me that no matter what weird charhs has inside ic an still > > open thosie fiels and make the neccessary replacements. > > Go back to 2.6 for the moment and defer learning about unicode until you're > done with th

Re: Replace and inserting strings within .txt files with the use of regex

2010-08-09 Thread Peter Otten
Νίκος wrote: > Please tell me that no matter what weird charhs has inside ic an still > open thosie fiels and make the neccessary replacements. Go back to 2.6 for the moment and defer learning about unicode until you're done with the conversion job. -- http://mail.python.org/mailman/listinfo/py

Re: Replace and inserting strings within .txt files with the use of regex

2010-08-09 Thread Νίκος
Please tell me that no matter what weird charhs has inside ic an still open thosie fiels and make the neccessary replacements. -- http://mail.python.org/mailman/listinfo/python-list

Re: Replace and inserting strings within .txt files with the use of regex

2010-08-09 Thread MRAB
Νίκος wrote: On 9 Αύγ, 16:52, MRAB wrote: Νίκος wrote: On 8 Αύγ, 17:59, Thomas Jollans wrote: Two problems here: str.replace doesn't use regular expressions. You'll have to use the re module to use regexps. (the re.sub function to be precise) '.' matches a single character. Any character, b

Re: Replace and inserting strings within .txt files with the use of regex

2010-08-09 Thread Νίκος
On 9 Αύγ, 16:52, MRAB wrote: > Νίκος wrote: > > On 8 Αύγ, 17:59, Thomas Jollans wrote: > > >> Two problems here: > > >> str.replace doesn't use regular expressions. You'll have to use the re > >> module to use regexps. (the re.sub function to be precise) > > >> '.'  matches a single character. An

Re: Replace and inserting strings within .txt files with the use of regex

2010-08-09 Thread Νίκος
On 9 Αύγ, 13:47, Peter Otten <__pete...@web.de> wrote: > Νίκος wrote: > > On 9 Αύγ, 13:06, Peter Otten <__pete...@web.de> wrote: > > >> > So since its utf-8 what the problem of opening it? > > >> Python says it's not, and I tend to believe it. > > > You are right! > > > I tried to do the same exact

Re: Replace and inserting strings within .txt files with the use of regex

2010-08-09 Thread MRAB
Νίκος wrote: On 8 Αύγ, 17:59, Thomas Jollans wrote: Two problems here: str.replace doesn't use regular expressions. You'll have to use the re module to use regexps. (the re.sub function to be precise) '.' matches a single character. Any character, but only one. '.*' matches as many characte

Re: Replace and inserting strings within .txt files with the use of regex

2010-08-09 Thread Peter Otten
Νίκος wrote: > On 9 Αύγ, 13:06, Peter Otten <__pete...@web.de> wrote: > >> > So since its utf-8 what the problem of opening it? >> >> Python says it's not, and I tend to believe it. > > You are right! > > I tried to do the same exact openign via IDLE enviroment and i goth > the encoding of the

Re: Replace and inserting strings within .txt files with the use of regex

2010-08-09 Thread Νίκος
On 9 Αύγ, 13:06, Peter Otten <__pete...@web.de> wrote: > > So since its utf-8 what the problem of opening it? > > Python says it's not, and I tend to believe it. You are right! I tried to do the same exact openign via IDLE enviroment and i goth the encoding of the file from there! >>> open("d:\

Re: Replace and inserting strings within .txt files with the use of regex

2010-08-09 Thread Peter Otten
Νίκος wrote: > On 9 Αύγ, 11:45, Peter Otten <__pete...@web.de> wrote: >> Νίκος wrote: >> > On 9 Αύγ, 10:38, Peter Otten <__pete...@web.de> wrote: >> >> Νίκος wrote: >> >> > Now the code looks as follows: >> >> > for currdir, files, dirs in os.walk('test'): >> >> >> > for f in files: >> >> >> > if

Re: Replace and inserting strings within .txt files with the use of regex

2010-08-09 Thread Νίκος
On 9 Αύγ, 11:45, Peter Otten <__pete...@web.de> wrote: > Νίκος wrote: > > On 9 Αύγ, 10:38, Peter Otten <__pete...@web.de> wrote: > >> Νίκος wrote: > >> > Now the code looks as follows: > >> > for currdir, files, dirs in os.walk('test'): > > >> > for f in files: > > >> > if f.endswith('php'): > > >>

Re: Replace and inserting strings within .txt files with the use of regex

2010-08-09 Thread Peter Otten
Νίκος wrote: > On 9 Αύγ, 10:38, Peter Otten <__pete...@web.de> wrote: >> Νίκος wrote: >> > Now the code looks as follows: >> > for currdir, files, dirs in os.walk('test'): >> >> > for f in files: >> >> > if f.endswith('php'): >> >> > # get abs path to filename >> > src_f = join(currdir, f) >> > I

Re: Replace and inserting strings within .txt files with the use of regex

2010-08-09 Thread Νίκος
On 9 Αύγ, 10:38, Peter Otten <__pete...@web.de> wrote: > Νίκος wrote: > > Now the code looks as follows: > > for currdir, files, dirs in os.walk('test'): > > >         for f in files: > > >                 if f.endswith('php'): > > >                         # get abs path to filename > >          

Re: Replace and inserting strings within .txt files with the use of regex

2010-08-09 Thread Peter Otten
Νίκος wrote: > Now the code looks as follows: > for currdir, files, dirs in os.walk('test'): > > for f in files: > > if f.endswith('php'): > > # get abs path to filename > src_f = join(currdir, f) > I just tried to test i

Re: Replace and inserting strings within .txt files with the use of regex

2010-08-09 Thread Νίκος
Now the code looks as follows: = #!/usr/bin/python import re, os, sys id = 0 # unique page_id for currdir, files, dirs in os.walk('test'): for f in files: if f.endswith('php'): # get abs path to filename

Re: Replace and inserting strings within .txt files with the use of regex

2010-08-08 Thread Νίκος
On 8 Αύγ, 17:59, Thomas Jollans wrote: > Two problems here: > > str.replace doesn't use regular expressions. You'll have to use the re > module to use regexps. (the re.sub function to be precise) > > '.'  matches a single character. Any character, but only one. > '.*' matches as many characters a

Re: Replace and inserting strings within .txt files with the use of regex

2010-08-08 Thread Joel Goldstick
� wrote: Hello dear Pythoneers, I have over 500 .php web pages in various subfolders under 'data' folder that i have to rename to .html and and ditch the '' tages from within and also insert a very first line of where id must be an identification unique number of every page for counter tracking

Re: Replace and inserting strings within .txt files with the use of regex

2010-08-08 Thread John S
On Aug 8, 10:59 am, Thomas Jollans wrote: > On 08/08/2010 04:06 PM, Νίκος wrote: > > > > > > > On 8 Αύγ, 15:40, Thomas Jollans wrote: > >> On 08/08/2010 01:41 PM, Νίκος wrote: > > >>> I was so dizzy and confused yesterday that i forgot to metnion that > >>> not only i need removal of php openign

Re: Replace and inserting strings within .txt files with the use of regex

2010-08-08 Thread Thomas Jollans
On 08/08/2010 04:06 PM, Νίκος wrote: > On 8 Αύγ, 15:40, Thomas Jollans wrote: >> On 08/08/2010 01:41 PM, Νίκος wrote: >> >>> I was so dizzy and confused yesterday that i forgot to metnion that >>> not only i need removal of php openign and closing tags but whaevers >>> data lurks inside those tags

Re: Replace and inserting strings within .txt files with the use of regex

2010-08-08 Thread Νίκος
On 8 Αύγ, 15:40, Thomas Jollans wrote: > On 08/08/2010 01:41 PM, Νίκος wrote: > > > I was so dizzy and confused yesterday that i forgot to metnion that > > not only i need removal of php openign and closing tags but whaevers > > data lurks inside those tags as well ebcause now with the 'counter.py

Re: Replace and inserting strings within .txt files with the use of regex

2010-08-08 Thread Thomas Jollans
On 08/08/2010 01:41 PM, Νίκος wrote: > I was so dizzy and confused yesterday that i forgot to metnion that > not only i need removal of php openign and closing tags but whaevers > data lurks inside those tags as well ebcause now with the 'counter.py' > script i wrote the html fiels would open ftm t

Re: Replace and inserting strings within .txt files with the use of regex

2010-08-08 Thread Νίκος
On 8 Αύγ, 13:13, Thomas Jollans wrote: > On 08/08/2010 11:21 AM, Νίκος wrote: > > > Please help me adjust it, if need extra modification for more php tags > > replacing. > > Have you tried it ? I haven't, but I see no immediate reason why it > wouldn't work with multiple PHP blocks. > > > > > > >

Re: Replace and inserting strings within .txt files with the use of regex

2010-08-08 Thread Thomas Jollans
On 08/08/2010 11:21 AM, Νίκος wrote: > Please help me adjust it, if need extra modification for more php tags > replacing. Have you tried it ? I haven't, but I see no immediate reason why it wouldn't work with multiple PHP blocks. > #!/usr/bin/python > > import cgitb; cgitb.enable() > import cgi

Re: Replace and inserting strings within .txt files with the use of regex

2010-08-08 Thread Thomas Jollans
On 08/08/2010 04:46 AM, rantingrick wrote: > *facepalm*! I really must stop Usenet-ing whilst consuming large > volumes of alcoholic beverages. THAT explains a lot. Cheers -- http://mail.python.org/mailman/listinfo/python-list

Re: Replace and inserting strings within .txt files with the use of regex

2010-08-08 Thread Νίκος
Script so far: #!/usr/bin/python import cgitb; cgitb.enable() import cgi, re, os print ( "Content-type: text/html; charset=UTF-8 \n" ) id = 0 # unique page_id for currdir, files, dirs in os.walk('data'): for f in files: if f.endswith('php'): # get abs path to filen

Re: Replace and inserting strings within .txt files with the use of regex

2010-08-08 Thread Νίκος
On 8 Αύγ, 11:09, Steven D'Aprano wrote: > On Sat, 07 Aug 2010 17:20:24 -0700, Νίκος wrote: > > I don't know how to handle such a big data replacing problem and cannot > > play with fire because those 500 pages are my cleints pages and data of > > those filesjust cannot be messes up. > > Take a bac

Re: Replace and inserting strings within .txt files with the use of regex

2010-08-08 Thread Steven D'Aprano
On Sat, 07 Aug 2010 17:20:24 -0700, Νίκος wrote: > I don't know how to handle such a big data replacing problem and cannot > play with fire because those 500 pages are my cleints pages and data of > those filesjust cannot be messes up. Take a backup copy of the files, and only edit the copies. Do

Re: Replace and inserting strings within .txt files with the use of regex

2010-08-07 Thread Νίκος
On 8 Αύγ, 05:56, John S wrote: >"How can I use RE string replacement to find PHP tags and convert them >to Django template tags?" No, not at all John, at least not yet! I have only 1 week that i'm learnign python(changing from php & perl) so i'm very fresh at this beautifull and straighforwrd la

Re: Replace and inserting strings within .txt files with the use of regex

2010-08-07 Thread Νίκος
On 8 Αύγ, 05:42, John S wrote: > If the 500 web pages are PHP only in the sense that there is only one > pair of tags in each file, surrounding the entire content, then > what you ask for is doable. First of all, thank you very much John for your BIG effort to help me(i'm still readign your post

Re: Replace and inserting strings within .txt files with the use of regex

2010-08-07 Thread John S
Even though I just replied above, in reading over the OP's message, I think the OP might be asking: "How can I use RE string replacement to find PHP tags and convert them to Django template tags?" Instead of saying source_contents = source_contents.replace(...) say this instead: import re de

Re: Replace and inserting strings within .txt files with the use of regex

2010-08-07 Thread rantingrick
On Aug 7, 8:42 pm, MRAB wrote: > That should be: > >    data = data.replace('    data = data.replace('?>', '') Yes, Thanks MRAB. I did forget that important detail. > Strings don't have an 'insert' method! *facepalm*! I really must stop Usenet-ing whilst consuming large volumes of alcoholic be

Re: Replace and inserting strings within .txt files with the use of regex

2010-08-07 Thread John S
On Aug 7, 8:20 pm, Νίκος wrote: > Hello dear Pythoneers, > > I have over 500 .php web pages in various subfolders under 'data' > folder that i have to rename to .html and and ditch the '' > tages from within and also insert a very first line of > where id must be an identification unique number o

Re: Replace and inserting strings within .txt files with the use of regex

2010-08-07 Thread Νίκος
# rename ALL php files to html in every subfolder of the folder 'data' os.rename('*.php', '*.html') # how to tell python to rename ALL php files to html to ALL subfolder under 'data' ? # current path of the file to be processed path = './data' # this must be somehow in a

Re: Replace and inserting strings within .txt files with the use of regex

2010-08-07 Thread MRAB
rantingrick wrote: On Aug 7, 7:20 pm, Νίκος wrote: Hello dear Pythoneers, I prefer Pythonista, but anywho.. I have over 500 .php web pages in various subfolders under 'data' folder that i have to rename to .html import os os.rename(old, new) and and ditch the '' tages from within path

Re: Replace and inserting strings within .txt files with the use of regex

2010-08-07 Thread rantingrick
On Aug 7, 7:20 pm, Νίκος wrote: > Hello dear Pythoneers, I prefer Pythonista, but anywho.. > I have over 500 .php web pages in various subfolders under 'data' > folder that i have to rename to .html import os os.rename(old, new) > and and ditch the '' tages from within path = 'some/valid/path

Replace and inserting strings within .txt files with the use of regex

2010-08-07 Thread Νίκος
Hello dear Pythoneers, I have over 500 .php web pages in various subfolders under 'data' folder that i have to rename to .html and and ditch the '' tages from within and also insert a very first line of where id must be an identification unique number of every page for counter tracking purposes.

Re: SEC proposes the use of Python and XML

2010-04-11 Thread Patrick Maupin
On Apr 11, 3:12 am, Cameron Simpson wrote: > On 10Apr2010 23:05, Chris Rebert wrote: > | On Sat, Apr 10, 2010 at 9:13 PM, Ted Larson Freeman| > wrote: > > | > This week the SEC proposed new requirements for asset-backed > | > securities that include the use of XML and

Re: SEC proposes the use of Python and XML

2010-04-11 Thread Terry Reedy
On 4/11/2010 12:13 AM, Ted Larson Freeman wrote: This week the SEC proposed new requirements for asset-backed securities that include the use of XML and Python: "The asset-level information would be provided according to proposed standards and in a tagged data format using eXtensible M

Re: SEC proposes the use of Python and XML

2010-04-11 Thread Cameron Simpson
On 10Apr2010 23:05, Chris Rebert wrote: | On Sat, Apr 10, 2010 at 9:13 PM, Ted Larson Freeman | wrote: | > This week the SEC proposed new requirements for asset-backed | > securities that include the use of XML and Python: | > | > "The asset-level information would be prov

  1   2   >