RE: delete from pattern to pattern if it contains match

2016-04-25 Thread Joaquin Alzola
() result_sms = send_sms(subscribers,shortCode,send_text) Reuse it. -Original Message- From: Python-list [mailto:python-list-bounces+joaquin.alzola=lebara@python.org] On Behalf Of Peter Otten Sent: 25 April 2016 11:14 To: python-list@python.org Subject: Re: delete from pattern to pattern

Re: delete from pattern to pattern if it contains match

2016-04-25 Thread harirammanohar
On Monday, April 25, 2016 at 4:58:15 PM UTC+5:30, Jussi Piitulainen wrote: > harirammano...@gmail.com writes: > > > On Monday, April 25, 2016 at 4:09:26 PM UTC+5:30, Jussi Piitulainen wrote: > >> Peter Otten writes: > >> > >> > harirammano...@gmail.com wrote: > >> > > >> >> Here is the code: >

Re: delete from pattern to pattern if it contains match

2016-04-25 Thread Jussi Piitulainen
harirammano...@gmail.com writes: > On Monday, April 25, 2016 at 4:09:26 PM UTC+5:30, Jussi Piitulainen wrote: >> Peter Otten writes: >> >> > harirammano...@gmail.com wrote: >> > >> >> Here is the code: >> > >> > Finally ;) >> >> :) > > name space issue can be resolved registering name space i

Re: delete from pattern to pattern if it contains match

2016-04-25 Thread harirammanohar
On Monday, April 25, 2016 at 4:09:26 PM UTC+5:30, Jussi Piitulainen wrote: > Peter Otten writes: > > > harirammano...@gmail.com wrote: > > > >> Here is the code: > > > > Finally ;) > > :) name space issue can be resolved registering name space i have no issue with that, only concern is xml

Re: delete from pattern to pattern if it contains match

2016-04-25 Thread Jussi Piitulainen
harirammano...@gmail.com writes: > On Monday, April 25, 2016 at 3:19:15 PM UTC+5:30, hariram...@gmail.com wrote: [- -] >> Here is the code: >> >> import xml.etree.ElementTree as ET >> ET.register_namespace("", "http://xmlns.jcp.org/xml/ns/javaee;) >> tree = ET.parse('sample.xml') >> root =

Re: delete from pattern to pattern if it contains match

2016-04-25 Thread Jussi Piitulainen
Peter Otten writes: > harirammano...@gmail.com wrote: > >> Here is the code: > > Finally ;) :) -- https://mail.python.org/mailman/listinfo/python-list

Re: delete from pattern to pattern if it contains match

2016-04-25 Thread Jussi Piitulainen
harirammano...@gmail.com writes: > On Monday, April 25, 2016 at 12:47:14 PM UTC+5:30, Jussi Piitulainen wrote: >> harirammano...@gmail.com writes: >> >> > Hi Jussi, >> > >> > i have seen you have written a definition to fulfill the requirement, >> > can we do this same thing using xml parser, as

Re: delete from pattern to pattern if it contains match

2016-04-25 Thread Peter Otten
harirammano...@gmail.com wrote: > Here is the code: Finally ;) > import xml.etree.ElementTree as ET > ET.register_namespace("", "http://xmlns.jcp.org/xml/ns/javaee;) I don't know what this does, but probably not what you expected. > tree = ET.parse('sample.xml') > root = tree.getroot() > >

Re: delete from pattern to pattern if it contains match

2016-04-25 Thread harirammanohar
On Monday, April 25, 2016 at 3:19:15 PM UTC+5:30, hariram...@gmail.com wrote: > On Monday, April 25, 2016 at 12:47:14 PM UTC+5:30, Jussi Piitulainen wrote: > > harirammano...@gmail.com writes: > > > > > Hi Jussi, > > > > > > i have seen you have written a definition to fulfill the requirement, >

Re: delete from pattern to pattern if it contains match

2016-04-25 Thread harirammanohar
On Monday, April 25, 2016 at 12:47:14 PM UTC+5:30, Jussi Piitulainen wrote: > harirammano...@gmail.com writes: > > > Hi Jussi, > > > > i have seen you have written a definition to fulfill the requirement, > > can we do this same thing using xml parser, as i have failed to > > implement the thing

Re: delete from pattern to pattern if it contains match

2016-04-25 Thread Jussi Piitulainen
harirammano...@gmail.com writes: > Hi Jussi, > > i have seen you have written a definition to fulfill the requirement, > can we do this same thing using xml parser, as i have failed to > implement the thing using xml parser of python if the file is having > the content as below... > > PUBLIC

Re: delete from pattern to pattern if it contains match

2016-04-25 Thread harirammanohar
On Friday, April 22, 2016 at 4:41:08 PM UTC+5:30, Jussi Piitulainen wrote: > Peter Otten writes: > > > harirammano...@gmail.com wrote: > > > >> On Thursday, April 21, 2016 at 7:03:00 PM UTC+5:30, Jussi Piitulainen > >> wrote: > >>> harirammano...@gmail.com writes: > >>> > >>> > On Monday, April

Re: delete from pattern to pattern if it contains match

2016-04-25 Thread harirammanohar
On Friday, April 22, 2016 at 3:20:53 PM UTC+5:30, Peter Otten wrote: > harirammano...@gmail.com wrote: > > >> @peter yes here it is not xml, but real data is an xml..believe me.. > > > > @peter this is the similar xml i am having, you can correlate. > > > >

Re: delete from pattern to pattern if it contains match

2016-04-22 Thread Jussi Piitulainen
Peter Otten writes: > harirammano...@gmail.com wrote: > >> On Thursday, April 21, 2016 at 7:03:00 PM UTC+5:30, Jussi Piitulainen >> wrote: >>> harirammano...@gmail.com writes: >>> >>> > On Monday, April 18, 2016 at 12:38:03 PM UTC+5:30, >>> > hariram...@gmail.com wrote: >>> >> HI All, >>> >>

Re: delete from pattern to pattern if it contains match

2016-04-22 Thread Peter Otten
harirammano...@gmail.com wrote: >> @peter yes here it is not xml, but real data is an xml..believe me.. > > @peter this is the similar xml i am having, you can correlate. > > https://tomcat.apache.org/tomcat-5.5-doc/appdev/web.xml.txt This is still too vague. If you post the code you actually

Re: delete from pattern to pattern if it contains match

2016-04-22 Thread Peter Otten
harirammano...@gmail.com wrote: > On Thursday, April 21, 2016 at 7:03:00 PM UTC+5:30, Jussi Piitulainen > wrote: >> harirammano...@gmail.com writes: >> >> > On Monday, April 18, 2016 at 12:38:03 PM UTC+5:30, >> > hariram...@gmail.com wrote: >> >> HI All, >> >> >> >> can you help me out in doing

Re: delete from pattern to pattern if it contains match

2016-04-22 Thread harirammanohar
On Friday, April 22, 2016 at 2:30:45 PM UTC+5:30, hariram...@gmail.com wrote: > On Thursday, April 21, 2016 at 4:55:18 PM UTC+5:30, Peter Otten wrote: > > harirammano...@gmail.com wrote: > > > > > On Monday, April 18, 2016 at 12:38:03 PM UTC+5:30, hariram...@gmail.com > > > wrote: > > >> HI All,

Re: delete from pattern to pattern if it contains match

2016-04-22 Thread harirammanohar
On Thursday, April 21, 2016 at 4:55:18 PM UTC+5:30, Peter Otten wrote: > harirammano...@gmail.com wrote: > > > On Monday, April 18, 2016 at 12:38:03 PM UTC+5:30, hariram...@gmail.com > > wrote: > >> HI All, > >> > >> can you help me out in doing below. > >> > >> file: > >> > >> guava > >>

Re: delete from pattern to pattern if it contains match

2016-04-22 Thread harirammanohar
On Thursday, April 21, 2016 at 7:03:00 PM UTC+5:30, Jussi Piitulainen wrote: > harirammano...@gmail.com writes: > > > On Monday, April 18, 2016 at 12:38:03 PM UTC+5:30, > > hariram...@gmail.com wrote: > >> HI All, > >> > >> can you help me out in doing below. > >> > >> file: > >> > >>

Re: delete from pattern to pattern if it contains match

2016-04-21 Thread Jussi Piitulainen
harirammano...@gmail.com writes: > On Monday, April 18, 2016 at 12:38:03 PM UTC+5:30, > hariram...@gmail.com wrote: >> HI All, >> >> can you help me out in doing below. >> >> file: >> >> guava >> fruit >> >> >> mango >> fruit >> >> >> orange >> fruit >> >> >> need to

Re: delete from pattern to pattern if it contains match

2016-04-21 Thread Peter Otten
harirammano...@gmail.com wrote: > On Monday, April 18, 2016 at 12:38:03 PM UTC+5:30, hariram...@gmail.com > wrote: >> HI All, >> >> can you help me out in doing below. >> >> file: >> >> guava >> fruit >> >> >> mango >> fruit >> >> >> orange >> fruit >> Is that literally what you have

Re: delete from pattern to pattern if it contains match

2016-04-21 Thread harirammanohar
On Monday, April 18, 2016 at 12:38:03 PM UTC+5:30, hariram...@gmail.com wrote: > HI All, > > can you help me out in doing below. > > file: > > guava > fruit > > > mango > fruit > > > orange > fruit > > > need to delete from start to end if it contains mango in a file...

Re: delete from pattern to pattern if it contains match

2016-04-18 Thread harirammanohar
lto:python-list-bounces+joaquin.alzola=lebara@python.org] On Behalf > Of harirammano...@gmail.com > Sent: 18 April 2016 08:08 > To: python-list@python.org > Subject: delete from pattern to pattern if it contains match > > > HI All, > > can you help me o

Re: delete from pattern to pattern if it contains match

2016-04-18 Thread harirammanohar
On Monday, April 18, 2016 at 1:19:43 PM UTC+5:30, Joaquin Alzola wrote: > Hi, > > Try to use the xml module. > > import xml.etree.ElementTree as ET > > That might help. > > BR > > Joaquin > > -Original Message- > > > HI All, > > can you help me out in doing below. > > file: > >

RE: delete from pattern to pattern if it contains match

2016-04-18 Thread Joaquin Alzola
@python.org Subject: delete from pattern to pattern if it contains match HI All, can you help me out in doing below. file: guava fruit mango fruit orange fruit need to delete from start to end if it contains mango in a file... output should be: guava fruit orange fruit Thank you

delete from pattern to pattern if it contains match

2016-04-18 Thread harirammanohar
HI All, can you help me out in doing below. file: guava fruit mango fruit orange fruit need to delete from start to end if it contains mango in a file... output should be: guava fruit orange fruit Thank you --

[issue26336] Expose regex bytecode as attribute of compiled pattern object

2016-02-20 Thread Jonathan Goble
Jonathan Goble added the comment: Noting for the record that, as I had brought up on python-ideas [1], in addition to simply exposing the raw code, it would be nice to have a public constructor for the compiled pattern type and a 'dis'-like module for support. The former would enable

[issue26336] Expose regex bytecode as attribute of compiled pattern object

2016-02-17 Thread Jonathan Goble
Jonathan Goble added the comment: It would indeed be marked as a CPython implementation detail, and with no guarantee of backward compatibility. Others (well, at least one other) have suggested the same on python-ideas. So a simple note in the accompanying documentation would suffice.

[issue26336] Expose regex bytecode as attribute of compiled pattern object

2016-02-17 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: Regex bytecode is implementation detail. It was 16-bit in narrow builds, but was changed to at least 32-bit in bugfix releases. It can be changed to 64-bit or to pack an argument with an opcode in one word. The implementation can not use the bytecode at

[issue26336] Expose regex bytecode as attribute of compiled pattern object

2016-02-16 Thread Paul Moore
Changes by Paul Moore : -- keywords: +easy ___ Python tracker ___ ___ Python-bugs-list

[issue26336] Expose regex bytecode as attribute of compiled pattern object

2016-02-10 Thread Jonathan Goble
atus: open title: Expose regex bytecode as attribute of compiled pattern object type: enhancement versions: Python 3.6 ___ Python tracker <rep...@bugs.python.org> <http://bugs.py

Observer pattern implementation in Python based on jQuery

2016-01-14 Thread fernando junior
Hi, I made an observer/pubsub pattern implementation in Python based on jQuery. It's available in https://github.com/fernandojunior/python-pattern-observer. Take a look! :) Fernando Felix https://br.linkedin.com/in/fernandofnjr -- https://mail.python.org/mailman/listinfo/python-list

[issue25584] a recursive glob pattern fails to list files in the current directory

2015-11-10 Thread Xavier de Gaye
Xavier de Gaye added the comment: New issue 25596 entered: regular files handled as directories in the glob module. Thanks for fixing this Serhiy. -- ___ Python tracker

[issue25584] a recursive glob pattern fails to list files in the current directory

2015-11-09 Thread Xavier de Gaye
Xavier de Gaye added the comment: FWIW the patch looks good to me. I find the code in glob.py difficult to read as it happily joins regular filenames together with os.path.join() or attempts to list the files contained into a regular file (sic). The attached diff makes the code more correct

[issue25584] a recursive glob pattern fails to list files in the current directory

2015-11-09 Thread Roundup Robot
Roundup Robot added the comment: New changeset 4532c4f37429 by Serhiy Storchaka in branch '3.5': Issue #25584: Fixed recursive glob() with patterns starting with '**'. https://hg.python.org/cpython/rev/4532c4f37429 New changeset 175cd763de57 by Serhiy Storchaka in branch 'default': Issue

[issue25584] a recursive glob pattern fails to list files in the current directory

2015-11-09 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: Please open new issue for glob() optimization Xavier. -- resolution: -> fixed stage: patch review -> resolved status: open -> closed ___ Python tracker

[issue25584] a recursive glob pattern fails to list files in the current directory

2015-11-09 Thread Xavier de Gaye
Xavier de Gaye added the comment: glob('invalid_dir/**', recursive=True) triggers the assert that was added by my patch in _rlistdir(). This new patch fixes this: when there is no magic character in the dirname part of a split(), and dirname is not an existing directory, then there is nothing

[issue25584] a recursive glob pattern fails to list files in the current directory

2015-11-09 Thread Serhiy Storchaka
Changes by Serhiy Storchaka : Added file: http://bugs.python.org/file40987/rglob_zero_dirs_2.patch ___ Python tracker ___

[issue25584] a recursive glob pattern fails to list files in the current directory

2015-11-08 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: I already don't remember if it was a deliberate design, or just implementation detail. In any case it is not documented. > I believe this behavior matches the documentation: No, it is not related. It is that './**/' will list only directories, not regular

[issue25584] a recursive glob pattern fails to list files in the current directory

2015-11-08 Thread R. David Murray
R. David Murray added the comment: I believe this behavior matches the documentation: "If the pattern is followed by an os.sep, only directories and subdirectories match." ('the pattern' being '**') I wonder if '***.pacnew' would work. -- nosy: +pitrou, r.da

[issue25584] a recursive glob pattern fails to list files in the current directory

2015-11-08 Thread Xavier de Gaye
"license" for more information. >>> import glob >>> len(glob.glob('./**/*.pacnew', recursive=True)) 20 >>> len(glob.glob('*.pacnew')) 9 >>> len(glob.glob('**/*.pacnew', recursive=True)) 11 The '**/*.pacnew' pattern does n

[issue25584] a recursive glob pattern fails to list files in the current directory

2015-11-08 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: Likely it was implementation artifact. Current implementation is simpler butter fitted existing glob design. The problem was that '**/a' should list 'a' and 'd/a', but '**/' should list only 'd/', and not ''. Here is a patch that makes '**' to match also

[issue25584] a recursive glob pattern fails to list files in the current directory

2015-11-08 Thread R. David Murray
R. David Murray added the comment: Ah, I see, 'pattern' there means the whole pattern. That certainly isn't clear. -- ___ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/i

Re: Object Pool design pattern

2015-07-23 Thread Laura Creighton
In a message of Thu, 23 Jul 2015 23:09:38 +0200, Abder-Rahman Ali writes: Hello, How can we implement the Object Pool design pattern in Python, especially when the pool consists of array data types? Thanks. Is your problem 'I don't know how to implement the Object Pool Design pattern at all

Object Pool design pattern

2015-07-23 Thread Abder-Rahman Ali
Hello, How can we implement the Object Pool design pattern in Python, especially when the pool consists of array data types? Thanks. -- https://mail.python.org/mailman/listinfo/python-list

Re: __new__() does not return anything, on singletong pattern

2015-03-12 Thread Mario Figueiredo
On Thu, 12 Mar 2015 16:31:12 +1100, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: Mario Figueiredo wrote: If this is supposed to be a singleton, you can't create more instances. The point of a singleton that there is only one instance (or perhaps a small number, two or three

Re: __new__() does not return anything, on singletong pattern

2015-03-12 Thread Mario Figueiredo
On Wed, 11 Mar 2015 16:47:32 -0700, Ethan Furman et...@stoneleaf.us wrote: You're code is good. Thanks for taking a weight off my shoulder. The only question is if you /really/ need a singleton -- and only you can answer that (although plenty of folks will tell you you don't ;) . Yeah. I

Re: __new__() does not return anything, on singletong pattern

2015-03-12 Thread Gregory Ewing
Mario Figueiredo wrote: It's just a cheap global, since is ubiquitous throughout the entire application, does behave like a singleton, and is a bit too expensive to create. A full map in the main application takes 3 or 4 seconds to instantiate and occupies around 2 Mb of memory. There's

Re: __new__() does not return anything, on singletong pattern

2015-03-12 Thread Gregory Ewing
Mario Figueiredo wrote: A different application, a map editor, needs to also instantiate an object of the class Map. But in this case the map needs to either be empty (if the user wants to create a new map), or loaded from the saved map file (if the user wants to edit an existing map). Then

Re: __new__() does not return anything, on singletong pattern

2015-03-12 Thread Gregory Ewing
Mario Figueiredo wrote: But PyCharm flags the assignment with a warning telling me that generate() does not return anything and the I lose code completion on the mmap variable. My guess is that there is a syntax error somewhere in your code that's confusing the IDE. -- Greg --

Re: __new__() does not return anything, on singletong pattern

2015-03-12 Thread Mario Figueiredo
On Thu, 12 Mar 2015 21:40:03 +1300, Gregory Ewing greg.ew...@canterbury.ac.nz wrote: Mario Figueiredo wrote: A different application, a map editor, needs to also instantiate an object of the class Map. But in this case the map needs to either be empty (if the user wants to create a new map),

Re: __new__() does not return anything, on singletong pattern

2015-03-12 Thread Mario Figueiredo
are so right! Been so long since I last created a singleton I forgot all about the idiomatic approaches to the pattern. Thanks Greg. That is much, much, better. -- https://mail.python.org/mailman/listinfo/python-list

Re: __new__() does not return anything, on singletong pattern

2015-03-12 Thread Steven D'Aprano
Mario Figueiredo wrote: It's just a cheap global, since is ubiquitous throughout the entire application, does behave like a singleton, and is a bit too expensive to create. A full map in the main application takes 3 or 4 seconds to instantiate and occupies around 2 Mb of memory. 2MB is not

Re: __new__() does not return anything, on singletong pattern

2015-03-12 Thread Mario Figueiredo
On Thu, 12 Mar 2015 21:41:16 +1300, Gregory Ewing greg.ew...@canterbury.ac.nz wrote: Mario Figueiredo wrote: But PyCharm flags the assignment with a warning telling me that generate() does not return anything and the I lose code completion on the mmap variable. My guess is that there is a

Re: __new__() does not return anything, on singletong pattern

2015-03-12 Thread Mario Figueiredo
to the idea of yet another singleton being born to this world. I myself despise the pattern. I think the GoF were drunk by the time they reached the Singleton. The whole Creational Patterns section was really only going downhill, anyways. Starts strong and ends up with the justin bieber of patterns

Re: __new__() does not return anything, on singletong pattern

2015-03-12 Thread Mario Figueiredo
On Thu, 12 Mar 2015 22:29:24 +1100, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: I would have a loadfile() method which takes a filename on disk, opens the file and passes the contents (or the open file object) to another method, load() to do the actual work: class Map: def

Re: __new__() does not return anything, on singletong pattern

2015-03-12 Thread Steven D'Aprano
Mario Figueiredo wrote: On Thu, 12 Mar 2015 16:31:12 +1100, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: Mario Figueiredo wrote: If this is supposed to be a singleton, you can't create more instances. The point of a singleton that there is only one instance (or perhaps a

__new__() does not return anything, on singletong pattern

2015-03-11 Thread Mario Figueiredo
I'm fairly new to Python, so I don't know if the following is me abusing the programming language idioms, or simply a mistake of my IDE code inspection routine. I have a singleton Map class which is defined like so: class Map: _instance = None def __new__(cls): if

Re: __new__() does not return anything, on singletong pattern

2015-03-11 Thread Ethan Furman
On 03/11/2015 04:33 PM, Mario Figueiredo wrote: The following code runs just fine. But PyCharm flags the assignment with a warning telling me that generate() does not return anything and the I lose code completion on the mmap variable. if __name__ == '__main__': mmap = Map.generate(12,

Re: __new__() does not return anything, on singletong pattern

2015-03-11 Thread Steven D'Aprano
Mario Figueiredo wrote: I'm fairly new to Python, so I don't know if the following is me abusing the programming language idioms, or simply a mistake of my IDE code inspection routine. I have a singleton Map class which is defined like so: class Map: _instance = None def

Re: suggestions for functional style (singleton pattern?)

2015-03-02 Thread Fabien
On 01.03.2015 06:05, Michael Torrie wrote: A module*is* a singleton pattern, particularly one that maintains state. I use sometimes use this feature for sharing config and other data between other modules (global state when it's required). I do this too, after some helping recommendations

Re: suggestions for functional style (singleton pattern?)

2015-03-02 Thread Mario Figueiredo
On Mon, 02 Mar 2015 11:19:06 +0100, Fabien fabien.mauss...@gmail.com wrote: On 01.03.2015 06:05, Michael Torrie wrote: A module*is* a singleton pattern, particularly one that maintains state. I use sometimes use this feature for sharing config and other data between other modules (global

Re: suggestions for functional style (singleton pattern?)

2015-03-02 Thread Michael Torrie
On 03/02/2015 03:19 AM, Fabien wrote: On 01.03.2015 06:05, Michael Torrie wrote: A module*is* a singleton pattern, particularly one that maintains state. I use sometimes use this feature for sharing config and other data between other modules (global state when it's required). I do

Re: suggestions for functional style (singleton pattern?)

2015-03-02 Thread Ian Kelly
On Mon, Mar 2, 2015 at 8:59 AM, Michael Torrie torr...@gmail.com wrote: Now I don't know of any way of implementing class-style properties on a module as you can do in a class, but if that were needed you would write a standard class and instantiate a singleton inside the module itself

Re: suggestions for functional style (singleton pattern?)

2015-03-01 Thread Steven D'Aprano
Mario Figueiredo wrote: (warning: Didn't bother prove-reading and spell chocking. Sorry...) Warning: didn't bother reading. Not sorry at all. -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: suggestions for functional style (singleton pattern?)

2015-03-01 Thread Steven D'Aprano
be calling the Borg pattern singletons. -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: suggestions for functional style (singleton pattern?)

2015-03-01 Thread Mario Figueiredo
On Mon, 02 Mar 2015 02:04:40 +1100, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: Mario Figueiredo wrote: (warning: Didn't bother prove-reading and spell chocking. Sorry...) Warning: didn't bother reading. Not sorry at all. Ohh.. how hurtful of you. It was 4:45 am when I posted

suggestions for functional style (singleton pattern?)

2015-02-28 Thread yves
every time. I have now started to use some kind of state pattern to alleviate this, here's a simplistic example: https://github.com/dorfsmay/state_pattern_for_debugging_python/blob/master/dirstats.py Are there better ways to address this? Any suggestion on this style? Thanks. -- http

Re: suggestions for functional style (singleton pattern?)

2015-02-28 Thread Paul Rubin
y...@zioup.com writes: Are there better ways to address this? Any suggestion on this style? I guess I don't completely understand the question. But one way to do a singleton in python is put the initialization code into a separate module. Then the first time you import the module, the code

Re: suggestions for functional style (singleton pattern?)

2015-02-28 Thread Michael Torrie
have to re-initialise every single objects every time. I have now started to use some kind of state pattern to alleviate this, here's a simplistic example: https://github.com/dorfsmay/state_pattern_for_debugging_python/blob/master/dirstats.py Are there better ways to address this? Any

Re: suggestions for functional style (singleton pattern?)

2015-02-28 Thread Gregory Ewing
y...@zioup.com wrote: Thanks. I hadn't realise singleton meant a class built such that it could not be instanciated more than once, It doesn't have to be, it could just be a class that you refrain from instantiating more than once. But as Michael Torrie said, it's rare to need to to that in

Re: suggestions for functional style (singleton pattern?)

2015-02-28 Thread yves
On 2015-02-28 19:19, Michael Torrie wrote: You say you are trying to use a singleton pattern, but your code does not appear to implement a singleton. From what I can read of your code, I call it a singletone because I only every create one object. I am not trying to use a singleton, I'm

Re: suggestions for functional style (singleton pattern?)

2015-02-28 Thread yves
such that it could not be instanciated more than once, I thought it corresponded to a pattern where only one object is ever created from a given class. But, if you ever wish to implement a singleton, the following pattern mostly works and is short and to the point: class Map

Re: suggestions for functional style (singleton pattern?)

2015-02-28 Thread Michael Torrie
a singleton are rare. Thanks. I hadn't realise singleton meant a class built such that it could not be instanciated more than once, I thought it corresponded to a pattern where only one object is ever created from a given class. Is not only one object is ever created from a given class the same

Re: suggestions for functional style (singleton pattern?)

2015-02-28 Thread Michael Torrie
On 02/28/2015 09:11 PM, y...@zioup.com wrote: On 2015-02-28 19:19, Michael Torrie wrote: You say you are trying to use a singleton pattern, but your code does not appear to implement a singleton. From what I can read of your code, I call it a singletone because I only every create one

Re: suggestions for functional style (singleton pattern?)

2015-02-28 Thread Mario Figueiredo
difficult, as as I have to re-initialise every single objects every time. I have now started to use some kind of state pattern to alleviate this, here's a simplistic example: https://github.com/dorfsmay/state_pattern_for_debugging_python/blob/master/dirstats.py Are there better ways to address

Re: try pattern for database connection with the close method

2015-02-22 Thread Mark Lawrence
On 22/02/2015 18:41, Mario Figueiredo wrote: On Sat, 21 Feb 2015 12:22:58 +, Mark Lawrence breamore...@yahoo.co.uk wrote: Use your context manager at the outer level. import sqlite3 as lite try: with lite.connect('data.db') as db: try: db.execute(sql, parms)

Re: try pattern for database connection with the close method

2015-02-22 Thread Skip Montanaro
On Sun, Feb 22, 2015 at 12:41 PM, Mario Figueiredo mar...@gmail.com wrote: The sqlite context manager doesn't close a database connection on exit. It only ensures, commits and rollbacks are performed. Sorry, I haven't paid careful attention to this thread, so perhaps this has already been

Re: try pattern for database connection with the close method

2015-02-22 Thread Mario Figueiredo
On Sat, 21 Feb 2015 12:22:58 +, Mark Lawrence breamore...@yahoo.co.uk wrote: Use your context manager at the outer level. import sqlite3 as lite try: with lite.connect('data.db') as db: try: db.execute(sql, parms) except lite.IntegrityError: raise

Re: try pattern for database connection with the close method

2015-02-22 Thread Mario Figueiredo
On Sun, 22 Feb 2015 13:15:09 -0600, Skip Montanaro skip.montan...@gmail.com wrote: Sorry, I haven't paid careful attention to this thread, so perhaps this has already been suggested, however... Can't you write your own class which delegates to the necessary sqlite3 bits and has a context manager

Re: try pattern for database connection with the close method

2015-02-22 Thread Mario Figueiredo
On Sat, 21 Feb 2015 16:22:36 +0100, Peter Otten __pete...@web.de wrote: Why would you care about a few lines? You don't repeat them, do you? Put the code into a function or a context manager and invoke it with Thanks for the suggestions that followed. --

Re: try pattern for database connection with the close method

2015-02-22 Thread Mario Figueiredo
On Sun, 22 Feb 2015 19:07:03 +, Mark Lawrence breamore...@yahoo.co.uk wrote: Looks like you're correct. Knock me down with a feather, Clevor Trevor. It took me by surprise when I first encountered it too. The rationale apparently is that the context manager is strictly a transactional

Re: try pattern for database connection with the close method

2015-02-21 Thread Peter Otten
Mario Figueiredo wrote: Hello all, I'm using the following pattern for db access that requires me to close the connection as soon as it is not needed: import sqlite3 as lite try: db = lite.connect('data.db') except lite.DatabaseError

Re: try pattern for database connection with the close method

2015-02-21 Thread Ian Kelly
On Sat, Feb 21, 2015 at 5:22 AM, Mark Lawrence breamore...@yahoo.co.uk wrote: On 21/02/2015 02:42, Mario Figueiredo wrote: Hello all, I'm using the following pattern for db access that requires me to close the connection as soon as it is not needed: import sqlite3 as lite

Re: try pattern for database connection with the close method

2015-02-21 Thread Peter Otten
Ian Kelly wrote: On Sat, Feb 21, 2015 at 5:22 AM, Mark Lawrence breamore...@yahoo.co.uk wrote: On 21/02/2015 02:42, Mario Figueiredo wrote: Hello all, I'm using the following pattern for db access that requires me to close the connection as soon as it is not needed: import

Re: try pattern for database connection with the close method

2015-02-21 Thread Ian Kelly
On Sat, Feb 21, 2015 at 8:27 AM, Peter Otten __pete...@web.de wrote: Ian Kelly wrote: On Sat, Feb 21, 2015 at 5:22 AM, Mark Lawrence breamore...@yahoo.co.uk wrote: try: with lite.connect('data.db') as db: try: db.execute(sql, parms) except lite.IntegrityError:

Re: try pattern for database connection with the close method

2015-02-21 Thread Peter Otten
Ian Kelly wrote: On Sat, Feb 21, 2015 at 8:27 AM, Peter Otten __pete...@web.de wrote: Ian Kelly wrote: On Sat, Feb 21, 2015 at 5:22 AM, Mark Lawrence breamore...@yahoo.co.uk wrote: try: with lite.connect('data.db') as db: try: db.execute(sql, parms) except

Re: try pattern for database connection with the close method

2015-02-21 Thread Mark Lawrence
On 21/02/2015 02:42, Mario Figueiredo wrote: Hello all, I'm using the following pattern for db access that requires me to close the connection as soon as it is not needed: import sqlite3 as lite try: db = lite.connect('data.db') except

Re: try pattern for database connection with the close method

2015-02-20 Thread Chris Kaynor
On Fri, Feb 20, 2015 at 6:42 PM, Mario Figueiredo mar...@gmail.com wrote: import sqlite3 as lite try: db = lite.connect('data.db') except lite.DatabaseError: raise OSError('database file corrupt or not found.') else: try:

try pattern for database connection with the close method

2015-02-20 Thread Mario Figueiredo
Hello all, I'm using the following pattern for db access that requires me to close the connection as soon as it is not needed: import sqlite3 as lite try: db = lite.connect('data.db') except lite.DatabaseError: raise OSError('database file

[issue23318] (compiled RegEx).split gives unexpected results if () in pattern

2015-01-25 Thread Dave Notman
', 'Sam', 'Jane', 'Zoe'] -- components: Regular Expressions messages: 234677 nosy: dnotmanj, ezio.melotti, mrabarnett priority: normal severity: normal status: open title: (compiled RegEx).split gives unexpected results if () in pattern type: behavior versions: Python 3.3

[issue23318] (compiled RegEx).split gives unexpected results if () in pattern

2015-01-25 Thread SilentGhost
SilentGhost added the comment: Looks like it works exactly as the docs[1] describe: re.split(r'\s*[+/;,]\s*|\s+and\s+', string) ['Dave', 'Sam', 'Jane', 'Zoe'] You're using capturing groups (parentheses) in your original regex which returns separators as part of a match. [1]

[OT]ORM Is an Offensive Anti-Pattern

2014-12-23 Thread Mark Lawrence
http://java.dzone.com/articles/orm-offensive-anti-pattern Please don't shoot the messenger. More importantly please don't make him write Java :) -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence -- https

What does (?Pname) pattern syntax do?

2014-11-10 Thread satishmlmlml
What does ?P and part1 match in the following piece of code? re.search('(?Ppart1\w*)/(?Ppart2\w*)', '...aaa/bbb/ccc]').groups() -- https://mail.python.org/mailman/listinfo/python-list

Re: What does (?Pname) pattern syntax do?

2014-11-10 Thread Ben Finney
satishmlm...@gmail.com writes: What does ?P and part1 match in the following piece of code? Learn about Python's regular expression features from the documentation URL:https://docs.python.org/3/library/re.html. Experiment with regular expressions using online tools such as

[issue22562] Singleton pattern for namedtuple

2014-10-06 Thread Mark Dickinson
Changes by Mark Dickinson dicki...@gmail.com: -- versions: +Python 3.5 -Python 3.4 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue22562 ___ ___

[issue22562] Singleton pattern for namedtuple

2014-10-06 Thread Mark Dickinson
Mark Dickinson added the comment: I don't think this is a good idea. Remember that Python classes are themselves mutable objects, so if a library that you happen to import creates a Point namedtuple with fields x and y and class-level modifications (extra attributes, patched-in methods), any

[issue22562] Singleton pattern for namedtuple

2014-10-06 Thread Barry A. Warsaw
Changes by Barry A. Warsaw ba...@python.org: -- nosy: +barry ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue22562 ___ ___ Python-bugs-list mailing

[issue22562] Singleton pattern for namedtuple

2014-10-06 Thread R. David Murray
R. David Murray added the comment: Agreed. If you want it to be a singleton in your code, use the singleton pattern in your code...but it is hard for me to see why that would be a good idea :) (ie: DRY). Globally, it does not seem to me that there are likely to be any significant number

[issue22562] Singleton pattern for namedtuple

2014-10-06 Thread Leo
Leo added the comment: A use case for the singleton pattern arises when - field names are known only at runtime, and - you have a large number of instances with the same field names. An example is the storage of metadata for datasets when a hashable type is needed. I agree

<    1   2   3   4   5   6   7   8   9   10   >