Re: Self healthcheck
On Wednesday, January 22, 2014 5:08:25 AM UTC+2, Chris Angelico wrote: > I assume you're talking about pure Python code, running under CPython. > (If you're writing an extension module, say in C, there are completely > different ways to detect reference leaks; and other Pythons will > behave slightly differently.) There's no way to detect truly > unreferenced objects, because they simply won't exist - not after a > garbage collection run, and usually sooner than that. But if you want > to find objects that you're somehow not using and yet still have live > references to, you'll need to define "using" in a way that makes > sense. Generally there aren't many ways that that can happen, so those > few places are candidates for a weak reference system (maybe you map a > name to the "master object" representing that thing, and you can > recreate the master object from the disk, so when nothing else is > referring to it, you can happily flush it out - that mapping is a good > candidate for weak references). > > But for most programs, don't bother. CPython is pretty good at keeping > track of its own references, so chances are you don't need to - and if > you're seeing the process's memory usage going up, it's entirely > possible you can neither detect nor correct the problem in Python code > (eg heap fragmentation). > ChrisA Hi Chris Yes the question was about CPython. But i am not after CPython leaks though detecting these would be good, but my own mistakes leading to accumulation of data in mutable structures. there will be few processes running python code standalone communicating across servers and every activity will be spread over time so i have to persistently keep record of activity and remove it later when activity is finished. In addition to checking objects directly i would like to analyze also app health indirectly via checking amount of data it holds. let say there is permanently 100 activities per second and typical object count figure is 1000 (in abstract units averaged over long enough time window), so i would check throughput and memory to see if my program is healthy in terms of leaking resources and generate log if it is not. Input to such module will be traffic events (whatever event significant to object creation). So i am looking for proper way to detect memory held by CPython app. And it would be good if memory can be deduced down to object/class name so blamed one could be identified and reported. Thanks Asaf -- https://mail.python.org/mailman/listinfo/python-list
Re: Early retirement project?
Le mardi 21 janvier 2014 18:34:44 UTC+1, Terry Reedy a écrit : > On 1/21/2014 6:38 AM, Tim Chase wrote: > > > On 2014-01-21 00:00, [email protected] wrote: > > >> Well, I retired early, and I guess now I've got some spare time to > > >> learn about programming, which always seemed rather mysterious. I > > >> am using an old mac as my main computer, and it runs os x 10.4 is > > >> this too old? It fills my needs, and I am on a fixed income and > > >> can't really afford to buy another. I think python would be a good > > >> starter language, based on what I've read on the net. > > > > > > It's certainly a great way to consume lots of hours :) > > > > > > Mac OS X 10.4 should come with an older version of Python > > > out-of-the-box. > > > > Someone else said that it comes with 2.5. That will be fine for many > > purposed. If you do use that, always make any classes you define a > > subclass of 'object' if nothing else. In other words, > > > > class MyClass(object): ... > > # instead of > > class MyClass: ... > > > > In Python 2, the second gives you an 'old-style' or 'classic' class. You > > do not need to learn about those. In Python 3, both forms give you > > new-style classes, which is what you should learn. > > > > There are a few other obsolete features to avoid, such as using strings > > for exceptions. > > > > > The install media should also include XCode if you > > > want to download the latest & greatest version of Python and install > > > that from source instead. > > > > If you can do that easily, I recommend starting with the latest Python > > 3, especially if you want to work with non-English (non-ascii) characters. > > In fact, Python just becomes the last tool I (would) recommend, especially for non-ascii users. jmf -- https://mail.python.org/mailman/listinfo/python-list
Re: Can post a code but afraid of plagiarism
So my question is if I am giving multiple inputs(a new device say for example) in a loop and creating a database(dictionary) for each new devices for example. I want subsequent devices to save their data(values only not keys) to the database of each of the already existing devices. How can I do that? Any hint?I have been stuck here for 3 days. -- https://mail.python.org/mailman/listinfo/python-list
Re: Can post a code but afraid of plagiarism
On Saturday, January 18, 2014 3:21:42 PM UTC-7, indar kumar wrote: > Hi, > > > > I want to show a code for review but afraid of plagiarism issues. Kindly, > suggest how can I post it for review here without masking it visible for > public Pleae give example also. I will be thankful. -- https://mail.python.org/mailman/listinfo/python-list
Re: Self healthcheck
On Wednesday, 22 January 2014, Asaf Las wrote: > On Wednesday, January 22, 2014 5:08:25 AM UTC+2, Chris Angelico wrote: > > I assume you're talking about pure Python code, running under CPython. > > (If you're writing an extension module, say in C, there are completely > > different ways to detect reference leaks; and other Pythons will > > behave slightly differently.) There's no way to detect truly > > unreferenced objects, because they simply won't exist - not after a > > garbage collection run, and usually sooner than that. But if you want > > to find objects that you're somehow not using and yet still have live > > references to, you'll need to define "using" in a way that makes > > sense. Generally there aren't many ways that that can happen, so those > > few places are candidates for a weak reference system (maybe you map a > > name to the "master object" representing that thing, and you can > > recreate the master object from the disk, so when nothing else is > > referring to it, you can happily flush it out - that mapping is a good > > candidate for weak references). > > > > But for most programs, don't bother. CPython is pretty good at keeping > > track of its own references, so chances are you don't need to - and if > > you're seeing the process's memory usage going up, it's entirely > > possible you can neither detect nor correct the problem in Python code > > (eg heap fragmentation). > > ChrisA > > Hi Chris > > Yes the question was about CPython. But i am not after CPython leaks > though detecting these would be good, but my own mistakes leading to > accumulation of data in mutable structures. > there will be few processes running python code standalone communicating > across servers and every activity will be spread over time so > i have to persistently keep record of activity and remove it later when > activity is finished. In addition to checking objects directly i would > like to analyze also app health indirectly via checking amount of data > it holds. let say there is permanently 100 activities per second and > typical object count figure is 1000 (in abstract units averaged over long > enough time window), so i would check throughput and memory to see if my > program is healthy in terms of leaking resources and generate log if it > is not. > Input to such module will be traffic events (whatever event significant > to object creation). > So i am looking for proper way to detect memory held by CPython app. And > it would be good if memory can be deduced down to object/class name so > blamed one could be identified and reported. > > There are some good tools recommended here: http://stackoverflow.com/questions/110259/which-python-memory-profiler-is-recommended But in general: use weak references wherever possible would be my advice. They not only prevent cycles but will highlight the kinds of bug in your code that is likely to cause the sort of problem you are worried about. -- https://mail.python.org/mailman/listinfo/python-list
Re: Self healthcheck
"Asaf Las" wrote in message news:[email protected]... > > Yes the question was about CPython. But i am not after CPython leaks > though detecting these would be good, but my own mistakes leading to > accumulation of data in mutable structures. > there will be few processes running python code standalone communicating > across servers and every activity will be spread over time so > i have to persistently keep record of activity and remove it later when > activity is finished. I had a similar concern. My main worry, which turned out to be well-founded, was that I would create an object as a result of some user input, but when the user had finished with it, and in theory it could be garbage-collected, in practice it would not be due to some obscure circular reference somewhere. For short-running tasks this is not a cause for concern, but for a long-running server these can build up over time and end up causing a problem. My solution was to log every time an object was created, with some self-identifying piece of information, and then log when it was deleted, with the same identifier. After running the program for a while I could then analyse the log and ensure that each creation had a corresponding deletion. The tricky bit was logging the deletion. It is a known gotcha in Python that you cannot rely on the __del__ method, and indeed it can cause a circular reference in itself which prevents the object from being garbage-collected. I found a solution somewhere which explained the use of a 'delwatcher' class. This is how it works - class MainObject: def __init__(self, identifier): self._del = delwatcher('MainObject', identifier) class delwatcher: def __init__(self, obj_type, identifier): self.obj_type = obj_type self.identifier = identifier log('{}: id={} created'.format(self.obj_type, self.identifier)) def __del__(self): log('{}: id={} deleted'.format(self.obj_type, self.identifier)) In this case calling __del__() is safe, as no reference to the main object is held. If you do find that an object is not being deleted, it is then trial-and-error to find the problem and fix it. It is probably a circular reference HTH Frank Millman -- https://mail.python.org/mailman/listinfo/python-list
Re: which data structure to use?
> Unlikely. Are you sure that .heap and .lookup contents are still in sync > with your modification? No it's not. Atfer having read about heapq it's clear why. Thanks for the hint. > allows you to delete random nodes, but the lowest() method will slow down as > it has to iterate over all dict values. Thanks a lot for the alternative class. I will go with two lists, each using one of the aproaches. In one list I always need to have only hte object with lowest .f. With the other list I may have to delete random nodes. So I can make perfect use of both classes. > One important caveat: both Nodes classes lead to data corruption if you > modify a .pos attribute while the node is in a Nodes instance. The same goes > for the first implementation and the .f attribute. That's fine. pos is static and identifies the node. Thanks again to all who responded. I learned a lot. -- https://mail.python.org/mailman/listinfo/python-list
Re: Separate Address number and name
On 22/01/2014 00:06, Shane Konings wrote: The following is a sample of the data. There are hundreds of lines that need to have an automated process of splitting the strings into headings to be imported into excel with theses headings See here for code that could simplify your extire task http://www.python-excel.org/ -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence -- https://mail.python.org/mailman/listinfo/python-list
Re: Early retirement project?
On 22/01/2014 08:18, [email protected] wrote: To my knowledge you are one of only two people who refuse to remove double line spacing from google. Just how bloody minded are you? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence -- https://mail.python.org/mailman/listinfo/python-list
any wheel experts here?
I'm trying to use --plat-name in python33 setup.py bdist_wheel --plat-name=win-amd64 I have a patched distutils package on my path that does allow me to do cross platform builds with normal distutils setup.py. However, I noticed immediately that my allegedly amd64 build is saying things like running bdist_wheel running build running build_py copying src\reportlab\lib\hyphen.mashed -> build\lib.win32-3.3\reportlab\lib running build_ext installing to build\bdist.win32\wheel running install running install_lib creating build\bdist.win32\wheel creating build\bdist.win32\wheel\reportlab creating build\bdist.win32\wheel\reportlab\fonts and later on it crashes with Traceback (most recent call last): File "setup.py", line 541, in main() File "setup.py", line 530, in main ext_modules = EXT_MODULES, File "c:\ux\ExeBuilder\py33\distutils\core.py", line 148, in setup dist.run_commands() File "c:\ux\ExeBuilder\py33\distutils\dist.py", line 929, in run_commands self.run_command(cmd) File "c:\ux\ExeBuilder\py33\distutils\dist.py", line 948, in run_command cmd_obj.run() File "C:\code\hg-repos\py33\lib\site-packages\wheel\bdist_wheel.py", line 207, in run archive_basename = self.get_archive_basename() File "C:\code\hg-repos\py33\lib\site-packages\wheel\bdist_wheel.py", line 156, in get_archive_basename impl_tag, abi_tag, plat_tag = self.get_tag() File "C:\code\hg-repos\py33\lib\site-packages\wheel\bdist_wheel.py", line 150, in get_tag assert tag == supported_tags[0] AssertionError so I guess that wheel doesn't support the idea of cross platform building on windows. Can anyone more on the bleeding edge confirm this? I can guess that somewhere in wheel the plat-name argument is not being passed on to distutils bdist, but in addition something about the platform name is causing the crash later on. -- Robin Becker -- https://mail.python.org/mailman/listinfo/python-list
Re: any wheel experts here?
On Wed, Jan 22, 2014 at 10:49:29AM +, Robin Becker wrote: > I'm trying to use --plat-name in > > python33 setup.py bdist_wheel --plat-name=win-amd64 > > I have a patched distutils package on my path that does allow me to > do cross platform builds with normal distutils setup.py. > > However, I noticed immediately that my allegedly amd64 build is saying things > like > > running bdist_wheel > running build > running build_py > copying src\reportlab\lib\hyphen.mashed -> build\lib.win32-3.3\reportlab\lib > running build_ext > installing to build\bdist.win32\wheel > running install > running install_lib > creating build\bdist.win32\wheel > creating build\bdist.win32\wheel\reportlab > creating build\bdist.win32\wheel\reportlab\fonts > > and later on it crashes with > > Traceback (most recent call last): > File "setup.py", line 541, in > main() > File "setup.py", line 530, in main > ext_modules = EXT_MODULES, > File "c:\ux\ExeBuilder\py33\distutils\core.py", line 148, in setup > dist.run_commands() > File "c:\ux\ExeBuilder\py33\distutils\dist.py", line 929, in run_commands > self.run_command(cmd) > File "c:\ux\ExeBuilder\py33\distutils\dist.py", line 948, in run_command > cmd_obj.run() > File > "C:\code\hg-repos\py33\lib\site-packages\wheel\bdist_wheel.py", line > 207, in run > archive_basename = self.get_archive_basename() > File > "C:\code\hg-repos\py33\lib\site-packages\wheel\bdist_wheel.py", line > 156, in get_archive_basename > impl_tag, abi_tag, plat_tag = self.get_tag() > File > "C:\code\hg-repos\py33\lib\site-packages\wheel\bdist_wheel.py", line > 150, in get_tag > assert tag == supported_tags[0] > AssertionError > > so I guess that wheel doesn't support the idea of cross platform > building on windows. Can anyone more on the bleeding edge confirm > this? In principle the wheel format support any kind of cross-building. It's possible though that the current wheel library has a bug that prevents this somehow or that you've monkeypatched distutils/setuptools in such a way that isn't compatible with bdist_wheel. It may be that the bdist_wheel command itself does not support cross-building but the wheel format certainly does, and perhaps the wheel library does if you import it directly. > I can guess that somewhere in wheel the plat-name argument is not > being passed on to distutils bdist, but in addition something about > the platform name is causing the crash later on. Sounds reasonable. I don't know the answer or whether anyone else on this list will but you can definitely find the relevant developers at this mailing list: https://mail.python.org/mailman/listinfo/distutils-sig/ Oscar -- https://mail.python.org/mailman/listinfo/python-list
Using a static library in a C extension for Python
Hello, working on OS X 10.8.5 Python 2.7 I've written a simple C extension for Python that uses the cairo graphic library. It works well, and I can call it from Python with no problem. The only drawback is that I need to have the cairo library installed on my system (so it seems my extension calls dynamically the cairo library). I believe this because it doesn't work on a system where cairo is not installed. Is it possible to link statically cairo to my extension, so that even if cairo is not installed on a computer, the code will run? I guess I would need to modify the setup.py file using distutils to compile cairo statically into my .so file? Or am I completely wrong? If someone has a hint... thanks! -- https://mail.python.org/mailman/listinfo/python-list
Re: [newbie] advice and comment wanted on first tkinter program
Jean Dupont Wrote in message: > Op maandag 20 januari 2014 07:24:31 UTC+1 schreef Chris Angelico: >> On Mon, Jan 20, 2014 at 3:04 PM, Jean Dupont wrote: >> > I started a thread "[newbie] starting geany from within idle does not >> > work" > I did try to do the same on my linux desktop computer, but the problem is, > it has another desktop environment (KDE4). In the rpi-environment it is > possible > (but it doesn't work) to change the default IDLE-editor by right-clicking > the idle-icon and choosing geany in stead of leafpad, however the same > can't be done > in KDE4, I hoped to find a similar setting once running IDLE in > Options-->Configure IDLE, but nothing there neither. I also looked > unsuccessfuly in the .idlerc-directory for a config-file. Hence my initial > question. > What does idle offer that Geary does not? Why not just run Geary from your terminal prompt? > -- DaveA -- https://mail.python.org/mailman/listinfo/python-list
Re: Can post a code but afraid of plagiarism
On 2014-01-22, Steven D'Aprano wrote: > Do you notice the assumption made? Let me highlight it for you: > >THE WORDS OF OTHERS > > The hidden assumption here is that *words are property*, that > they belong to whomever first publishes them. Having now > written those few words, nobody else is permitted to use those > same words in the same order without crediting me. Failure to > credit me is a sin of the highest order, enough to get you > kicked out of your university, your name blackened. Unless, of > course, somebody else wrote those words before me, in which > case *my ignorance* of that earlier usage does not diminish the > magnitude of my sin. In that regard, plagiarism is rather like > patent infringement. >From The Cemetery Gates, The Smiths: You say, "Ere thrice the sun done salutation to to the dawn," and you claim these words as your own. But I've read well and I've heard them said one hundred times maybe less maybe more. [...] You say, "Ere long done do does did;" words which could only be your own, and then produce a text from whence it was ripped [...] When grading essays my wife is far more likely to detect the first case. > We do not know how strict the OP's college is about so-called > plagiarism, whether they only intend to come down on outright > copying of significant bodies of code, or whether they have a > tendency to go after trivial borrowing of simple idioms or > minor duplication of insignificant portions of the program. (If > I walk a linked list using mynode = mynode.next, and you use > the same variable names, is that an indication of copying?) > Without knowing what the OP's college considers plagiarism, how > can judge the OP's reaction to it? Obvious copying of another person's program, nearly verbatim, is most likely to be detected. Well, that and submitting one of the entrapment-purposed answers that are sometimes made availalbe here and elsewhere. -- Neil Cerutti -- https://mail.python.org/mailman/listinfo/python-list
Re: Early retirement project?
On 2014-01-22, [email protected] wrote: > In fact, Python just becomes the last tool I (would) > recommend, especially for non-ascii users. Have a care, jmf. People unfamiliar with your opinions might take that seriously. -- Neil Cerutti -- https://mail.python.org/mailman/listinfo/python-list
Re: Early retirement project?
On Wed, Jan 22, 2014 at 1:18 AM, wrote: > In fact, Python just becomes the last tool I (would) > recommend, especially for non-ascii users. That's right - only Americans should use Python! -- https://mail.python.org/mailman/listinfo/python-list
Re: Early retirement project?
On Wednesday, January 22, 2014 7:15:34 PM UTC+5:30, Larry wrote: > On Wed, Jan 22, 2014 at 1:18 AM, wrote: > > In fact, Python just becomes the last tool I (would) > > recommend, especially for non-ascii users. > That's right - only Americans should use Python! Of whom the firstest and worstest is Guido v Rossum -- https://mail.python.org/mailman/listinfo/python-list
Re: any wheel experts here?
On Wednesday, January 22, 2014 4:31:32 PM UTC+5:30, Oscar Benjamin wrote: > Sounds reasonable. I don't know the answer or whether anyone else on this list > will but you can definitely find the relevant developers at this mailing list: > https://mail.python.org/mailman/listinfo/distutils-sig/ I believe the wheel/pip/virtualenv guys are on this list https://groups.google.com/forum/#!forum/python-virtualenv -- https://mail.python.org/mailman/listinfo/python-list
Re: Early retirement project?
On 22/01/2014 08:18, [email protected] wrote: In fact, Python just becomes the last tool I (would) recommend, especially for non-ascii users. https://www.youtube.com/watch?v=7aItpjF5vXc dedicated to jmf and his knowledge of unicode and Python. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence -- https://mail.python.org/mailman/listinfo/python-list
Re: [newbie] advice and comment wanted on first tkinter program
Op maandag 20 januari 2014 10:17:15 UTC+1 schreef Alister: > On Sun, 19 Jan 2014 20:04:05 -0800, Jean Dupont wrote: > > > Op zaterdag 18 januari 2014 16:12:41 UTC+1 schreef Oscar Benjamin: > >> On 18 January 2014 14:52, Jean Dupont wrote: > >> > > >> > Thanks Peter and Terry Jan for the useful suggestions. One thing > >> > which I > >> >find a bit weird: when asking for Python-help concerning raspberry pi > >> >code > >> > or problems, a lot of people don't seem to be interested in helping > >> > out, > >> > that's of course their choice, but maybe they don't seem to be aware > >> > the raspberry pi is often the motivation for starting to learn to > >> > program in > >> >Python. And as such such a reaction is a bit disappointing. > >> Hi Jean, > >> What makes you say that? Did you previously ask questions about > >> Rasberry Pi code on this list? > > It was not about code but about python-coding in IDLE (that's the > > default on raspbian): > > I started a thread "[newbie] starting geany from within idle does not > > work" both here and in the raspberry pi forum. I just wondered why I > > never got an answer concerning that topic. > > > >> If you did I wouldn't have answered those questions because I've never > >> used a Raspberry Pi and know nothing about them (except that they > >> encourage using Python somehow). I think that there's actually a list > >> that is specifically for Raspberry Pi Python questions that might be > >> more helpful although I don't know what it is... > > Here is the url to that forum > > > > http://www.raspberrypi.org/forum/ > > > > kind regards, > > jean > > Personally use Geany stand alone and not under idle, pressing F5 should > save & run the code you are currently editing. Would running under idle > give any other benefits? I don't know yet, but I just wanted to try out which of the following three I'd like best: 1. idle+leafpad 2. idle+geany 3. plain geany It's normal for a newbie to start with (1) as that is the default on raspbian, however I still don't understand why (2) does not work... kind regards, jean -- https://mail.python.org/mailman/listinfo/python-list
Re: Separate Address number and name
On Tue, 21 Jan 2014 15:49:16 -0800, Shane Konings wrote: > I have the following sample from a data set and I am looking to split > the address number and name into separate headings as seen below. > > FarmIDAddress 1 1067 Niagara Stone 24260 Mountainview 3 25 Hunter 4 > 1091 Hutchinson 5 5172 Green Lane 6 500 Glenridge 7 471 Foss 8 758 > Niagara Stone 9 3836 Main 101025 York > > > FarmIDAddressNumAddressName 1 1067 Niagara Stone 2 4260 > Mountainview 3 25Hunter 4 1091 Hutchinson 5 > 5172 Green Lane 6500 Glenridge 7 471 Foss > 8 758 Niagara Stone 9 3836 Main 10 1025 York > > I have struggled with this for a while and know there must be a simple > method to achieve this result. Unfortunately the vagaries of nntp, my client and the google nntp posting host are such that I can't discern the format of your data from your post. However, if as I think you have a text field that is always: <1 or more digits><1 or more spaces> where you want to capture the initial "1 or more digits" and "the rest" as 2 data elements then this should be possible with a simple re: (\d+)\s+(.*) If you have numeric id, whitespace, numeric addr bit, whitespace, the rest, then you may need something more like: (\d+)\s+(\d+)\s+(.*) The assumption is that it's not necessary to hold your hand through the whole looping through the input and applying the re to each line, then reading the captured bits and using them process. -- Denis McMahon, [email protected] -- https://mail.python.org/mailman/listinfo/python-list
Re: [newbie] advice and comment wanted on first tkinter program
On Wed, 22 Jan 2014 06:45:53 -0800, Jean Dupont wrote: > Op maandag 20 januari 2014 10:17:15 UTC+1 schreef Alister: >> On Sun, 19 Jan 2014 20:04:05 -0800, Jean Dupont wrote: >> >> > Op zaterdag 18 januari 2014 16:12:41 UTC+1 schreef Oscar Benjamin: >> >> On 18 January 2014 14:52, Jean Dupont >> >> wrote: >> >> > >> >> > Thanks Peter and Terry Jan for the useful suggestions. One thing >> >> > which I >> >> >find a bit weird: when asking for Python-help concerning raspberry >> Personally use Geany stand alone and not under idle, pressing F5 >> should save & run the code you are currently editing. Would running >> under idle give any other benefits? > I don't know yet, but I just wanted to try out which of the following > three I'd like best: > 1. idle+leafpad 2. idle+geany 3. plain geany > > It's normal for a newbie to start with (1) as that is the default on > raspbian, > however I still don't understand why (2) does not work... > When I play with my Pi I tend to use another computer for all my editing (sshfs is a quick & easy way for me to mount the necessary parts of the PI file system so I don't have to keep transferring files) -- People in general do not willingly read if they have anything else to amuse them. -- S. Johnson -- https://mail.python.org/mailman/listinfo/python-list
Re: Self healthcheck
On Wednesday, January 22, 2014 10:43:39 AM UTC+2, Nicholas wrote: > There are some good tools recommended here: > http://stackoverflow.com/questions/110259/which-python-memory-profiler-is-recommended > But in general: use weak references wherever possible would be > my advice. They not only prevent cycles but will highlight the > kinds of bug in your code that is likely to cause the sort of > problem you are worried about. Thanks! i will look into these! -- https://mail.python.org/mailman/listinfo/python-list
SIngleton from __defaults__
Hi Inspired by "Modifying the default argument of function" https://groups.google.com/forum/#!topic/comp.lang.python/1xtFE6uScaI is it possible to create singleton using construct below : def singleton_provider(x = [None]): if singleton_provider.__defaults__[0][0] == None: singleton_provider.__defaults__[0][0] = SomeClass() return singleton_provider.__defaults__[0][0] and question - how to make it work in multithreaded app when multiple threads are racing to create it first? Thanks Asaf -- https://mail.python.org/mailman/listinfo/python-list
Re: Self healthcheck
On Wednesday, January 22, 2014 10:56:30 AM UTC+2, Frank Millman wrote:
>
> class MainObject:
> def __init__(self, identifier):
> self._del = delwatcher('MainObject', identifier)
> class delwatcher:
> def __init__(self, obj_type, identifier):
> self.obj_type = obj_type
> self.identifier = identifier
> log('{}: id={} created'.format(self.obj_type, self.identifier))
> def __del__(self):
> log('{}: id={} deleted'.format(self.obj_type, self.identifier))
> If you do find that an object is not being deleted, it is then
> trial-and-error to find the problem and fix it. It is probably a circular
> reference
>
> Frank Millman
Thanks Frank. Good approach!
One question - You could do:
class MainObject:
def __init__(self, identifier):
self._del = delwatcher(self)
then later
class delwatcher:
def __init__(self, tobject):
self.obj_type = type(tobject)
self.identifier = id(tobject)
...
when creating delwatcher. Was there special reason to not to use them?
is this because of memory is reused when objects are deleted
and created again so same reference could be for objects created
in different time slots?
Thanks
Asaf
--
https://mail.python.org/mailman/listinfo/python-list
Re: SIngleton from __defaults__
On Thu, Jan 23, 2014 at 3:07 AM, Asaf Las wrote: > is it possible to create singleton using construct below : > > def singleton_provider(x = [None]): > if singleton_provider.__defaults__[0][0] == None: > singleton_provider.__defaults__[0][0] = SomeClass() > return singleton_provider.__defaults__[0][0] > Why not simply: def get_singleton(x = SomeClass()): return x Or even: singleton = SomeClass() ? Neither of the above provides anything above the last one, except for late creation. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: Can post a code but afraid of plagiarism
On Saturday, January 18, 2014 3:21:42 PM UTC-7, indar kumar wrote: > Hi, > > > > I want to show a code for review but afraid of plagiarism issues. Kindly, > suggest how can I post it for review here without masking it visible for > public This is a gratuitous arp request http://wiki.wireshark.org/Gratuitous_ARP sent by PC1 is informing other hosts of its MAC and IP addresses. Any hosts already in existence have their caches updated as needed. The first config call has no other hosts to update, so all it does is create a dictionary entry with its host id as the key. Its cache table is created as an empty dictionary. Subsequent config call update all other hosts' cache tables. Each host has its own ARP cache table. -- https://mail.python.org/mailman/listinfo/python-list
Re: Can post a code but afraid of plagiarism
On Saturday, January 18, 2014 3:21:42 PM UTC-7, indar kumar wrote: > Hi, > > > > I want to show a code for review but afraid of plagiarism issues. Kindly, > suggest how can I post it for review here without masking it visible for > public Description of each of the commands: • config ◦ Parameters: ▪ is the host's ARP cache timeout, in seconds ◦ Actions: ▪ Update simulator's configuration database. • If already exists, its information should be updated. Otherwise, it should be added. ▪ Print “ connected.” ▪ Have the host send a gratuitous ARP request . • If any other hosts have an outdated entry for the MAC or IP address, they should update their caches. • If there are any responses to that request, that means that somebody else has this IP address. If that is the case, you should print: Error: detected IP address conflict. It will be disconnected. Then, you should “disconnect” the host from the simulated network, in order to prevent further problems. You can implement this by removing it from the configuration database. ◦ Note: any ARP packets generated by the command should be printed in the previously specified format Sample Output: config Please enter PC1 01:01:01:01:01:01 192.168.0.1 200 PC1 connected. ARP request 01:01:01:01:01:01 FF:FF:FF:FF:FF:FF 192.168.0.1 192.168.0.1 -- https://mail.python.org/mailman/listinfo/python-list
Re: Can post a code but afraid of plagiarism
On Wednesday, January 22, 2014 2:06:17 PM UTC+5:30, indar kumar wrote: > So my question is if I am giving multiple inputs(a new device say > for example) in a loop and creating a database(dictionary) for each > new devices for example. I want subsequent devices to save their > data(values only not keys) to the database of each of the already > existing devices. How can I do that? Any hint?I have been stuck here > for 3 days. I suggest that for starters you forget about (real) DBMSes and just use some lightweight data storage. Some examples of these: 1. json 2. yaml 3. pickle 4. ini file [I like yaml best but it needs to be installed] Second I suggest you forget about your assignment/problem, and just practice getting python data structures -- mainly lists and dicts into your chosen format. Third forget about the above and just solve the problem with internal python data structures. Then come back here and ask! -- https://mail.python.org/mailman/listinfo/python-list
Re: SIngleton from __defaults__
On Wednesday, January 22, 2014 6:18:57 PM UTC+2, Chris Angelico wrote: > On Thu, Jan 23, 2014 at 3:07 AM, Asaf Las wrote: > > Why not simply: > def get_singleton(x = SomeClass()): > return x > Or even: > singleton = SomeClass() > ? Neither of the above provides anything above the last one, except > for late creation. > > ChrisA Actually need was to have some interface to running independent threads to give same and once created object always. For first - SomeClass's object will be created whenever there will be call to get_singleton(). For second, again it is free to create it whenever someone (thread) wish. Hmmm, use case was to create persistent counter in multithreaded app accessing single file where incrementing integer is stored. When my imagination expanded it onto multiprocessing mess i ended up using sqlite access to DB in exclusive transaction mode. But this was not pythonic :-) Asaf -- https://mail.python.org/mailman/listinfo/python-list
Re: Can post a code but afraid of plagiarism
On Saturday, January 18, 2014 3:21:42 PM UTC-7, indar kumar wrote: > Hi, > > > > I want to show a code for review but afraid of plagiarism issues. Kindly, > suggest how can I post it for review here without masking it visible for > public Any link related to such type of problems or logic would be helpful -- https://mail.python.org/mailman/listinfo/python-list
Re: Can post a code but afraid of plagiarism
On Saturday, January 18, 2014 3:21:42 PM UTC-7, indar kumar wrote: > Hi, > > > > I want to show a code for review but afraid of plagiarism issues. Kindly, > suggest how can I post it for review here without masking it visible for > public I need to implement this with simple dictionarie. I know use of dictionaries, lists and tuples. But, I am not able to create a logic in a loop. I mean how the other hosts would get MAC and IP of subsequent hosts in each turn. -- https://mail.python.org/mailman/listinfo/python-list
Re: Can post a code but afraid of plagiarism
On Saturday, January 18, 2014 3:21:42 PM UTC-7, indar kumar wrote: > Hi, > > > > I want to show a code for review but afraid of plagiarism issues. Kindly, > suggest how can I post it for review here without masking it visible for > public Just one hint and I have made the design for whole code. Just stuck at this part -- https://mail.python.org/mailman/listinfo/python-list
Re: SIngleton from __defaults__
On Thursday, January 23, 2014 12:37:36 AM UTC+8, Asaf Las wrote: > On Wednesday, January 22, 2014 6:18:57 PM UTC+2, Chris Angelico wrote: > > > On Thu, Jan 23, 2014 at 3:07 AM, Asaf Las wrote: > > > > > > Why not simply: > > > def get_singleton(x = SomeClass()): > > > return x > > > Or even: > > > singleton = SomeClass() > > > ? Neither of the above provides anything above the last one, except > > > for late creation. > > > > > > ChrisA > > > > Actually need was to have some interface to running independent threads > > to give same and once created object always. > > > > For first - SomeClass's object will be created whenever there will be > > call to get_singleton(). > > For second, again it is free to create it whenever someone (thread) > > wish. > > > > Hmmm, use case was to create persistent counter in multithreaded app > > accessing single file where incrementing integer is stored. > > When my imagination expanded it onto multiprocessing mess i ended up > > using sqlite access to DB in exclusive transaction mode. > > But this was not pythonic :-) > > > > Asaf In a high level language such as Python, functions and class initilizers are the first class objects. Don't you get the proof? Everyting OOP is equivalent to everything functional but it is much trivial to debug by the designer than the old grandma lisp. -- https://mail.python.org/mailman/listinfo/python-list
Re: Using a static library in a C extension for Python
On Wednesday, January 22, 2014 7:01:50 PM UTC+8, lgabiot wrote: > Hello, > > > > working on OS X 10.8.5 > > Python 2.7 > > > > I've written a simple C extension for Python that uses the cairo graphic > > library. > > It works well, and I can call it from Python with no problem. > > The only drawback is that I need to have the cairo library installed on > > my system (so it seems my extension calls dynamically the cairo library). > > I believe this because it doesn't work on a system where cairo is not > > installed. > > > > Is it possible to link statically cairo to my extension, so that even if > > cairo is not installed on a computer, the code will run? > > > > I guess I would need to modify the setup.py file using distutils to > > compile cairo statically into my .so file? > > > > Or am I completely wrong? > > > > If someone has a hint... > > > > thanks! Check the C source code generated by Pyrex and check cython for what u want, but I did try that out in any mobile phone or flat panel programming. -- https://mail.python.org/mailman/listinfo/python-list
Re: Separate Address number and name
On Tue, 21 Jan 2014 16:06:56 -0800, Shane Konings wrote: > The following is a sample of the data. There are hundreds of lines that > need to have an automated process of splitting the strings into headings > to be imported into excel with theses headings > > ID Address StreetNum StreetName SufType Dir City Province > PostalCode Ok, the following general method seems to work: First, use a regex to capture two numeric groups and the rest of the line separated by whitespace. If you can't find all three fields, you have unexpected data format. re.search( r"(\d+)\s+(\d+)\s+(.*)", data ) Second, split the rest of the line on a regex of comma + 0 or more whitespace. re.split( r",\s+", data ) Check that the rest of the line has 3 or 4 bits, otherwise you have an unexpected lack or excess of data fields. Split the first bit of the rest of the line into street name and suffix/ type. If you can't split it, use it as the street name and set the suffix/ type to blank. re.search( r"(.*)\s+(\w+)", data ) If there are 3 bits in rest of line, set direction to blank, otherwise set direction to the second bit. Set the city to the last but one bit of the rest of the line. Capture one word followed by two words in the last bit of the rest of the line, and use these as the province and postcode. re.search( r"(\w+)\s+(\w+\s+\w+)", data ) Providing none of the searches or the split errored, you should now have the data fields you need to write. The easiest way to write them might be to assemble them as a list and use the csv module. I'm assuming you're capable of working out from the help on the python re module what to use for each data, and how to access the captured results of a search, and the results of a split. I'm also assuming you're capable of working out how to use the csv module from the documentation. If you're not, then either go back and ask your lecturer for help, or tell your boss to hire a real programmer for his quick and easy coding jobs. -- Denis McMahon, [email protected] -- https://mail.python.org/mailman/listinfo/python-list
No overflow in variables?
Hi everyone. First of all sorry if my english is not good.
I have a question about something in Python I can not explain:
in every programming language I know (e.g. C#) if you exceed the max-value of a
certain type (e.g. a long-integer) you get an overflow. Here is a simple
example in C#:
static void Main(string[] args)
{
Int64 x = Int64.MaxValue;
Console.WriteLine(x); // output: 9223372036854775807
x = x * 2;
Console.WriteLine(x); // output: -2 (overflow)
Console.ReadKey();
}
Now I do the same with Python:
x = 9223372036854775807
print(type(x)) #
x = x * 2 # 18446744073709551614
print(x) #
print(type(x))
and I get the right output without overflow and the type is always a 'int'.
How does Python manages internally the types and their values? Where are they
stored?
Thank you for your help :)
--
https://mail.python.org/mailman/listinfo/python-list
Re: No overflow in variables?
On Wed, Jan 22, 2014 at 11:09 AM, Philip Red
wrote:
> Hi everyone. First of all sorry if my english is not good.
> I have a question about something in Python I can not explain:
> in every programming language I know (e.g. C#) if you exceed the max-value of
> a certain type (e.g. a long-integer) you get an overflow. Here is a simple
> example in C#:
>
> static void Main(string[] args)
> {
> Int64 x = Int64.MaxValue;
> Console.WriteLine(x); // output: 9223372036854775807
> x = x * 2;
> Console.WriteLine(x); // output: -2 (overflow)
> Console.ReadKey();
> }
>
> Now I do the same with Python:
>
> x = 9223372036854775807
> print(type(x)) #
> x = x * 2 # 18446744073709551614
> print(x) #
> print(type(x))
>
> and I get the right output without overflow and the type is always a 'int'.
> How does Python manages internally the types and their values? Where are they
> stored?
>
> Thank you for your help :)
This may help you understand:
http://www.python.org/dev/peps/pep-0237/
--
https://mail.python.org/mailman/listinfo/python-list
Re:No overflow in variables?
Philip Red Wrote in message:
> Hi everyone. First of all sorry if my english is not good.
> I have a question about something in Python I can not explain:
> in every programming language I know (e.g. C#) if you exceed the max-value of
> a certain type (e.g. a long-integer) you get an overflow. Here is a simple
> example in C#:
>
> static void Main(string[] args)
> {
> Int64 x = Int64.MaxValue;
> Console.WriteLine(x); // output: 9223372036854775807
> x = x * 2;
> Console.WriteLine(x); // output: -2 (overflow)
> Console.ReadKey();
> }
>
> Now I do the same with Python:
>
> x = 9223372036854775807
> print(type(x)) #
> x = x * 2 # 18446744073709551614
> print(x) #
> print(type(x))
>
> and I get the right output without overflow and the type is always a 'int'.
> How does Python manages internally the types and their values? Where are they
> stored?
>
> Thank you for your help :)
>
In python, every value is an object. Some, like lists, can grow
over time, and there's no specific upper limit in size. Others,
like int, or string, are immutable, so the constructor can
calculate just how much space is needed.
In java, and I believe in C#, they make a distinction between
unboxed and boxed integers. The former are NOT objects, and have
a specific upper bound, generally based on some power of
2.
--
DaveA
--
https://mail.python.org/mailman/listinfo/python-list
Re: Early retirement project?
[email protected] writes: > In fact, Python just becomes the last tool I (would) > recommend, especially for non-ascii users. > > jmf In fact, Python 3 is one of the best programming tools for non-ASCII users. -- Piet van Oostrum WWW: http://pietvanoostrum.com/ PGP key: [8DAE142BE17999C4] -- https://mail.python.org/mailman/listinfo/python-list
Re: No overflow in variables?
On Thu, Jan 23, 2014 at 5:09 AM, Philip Red wrote: > Now I do the same with Python: > > x = 9223372036854775807 > print(type(x)) # > x = x * 2 # 18446744073709551614 > print(x) # > print(type(x)) > > and I get the right output without overflow and the type is always a 'int'. > How does Python manages internally the types and their values? Where are they > stored? The Python integer type stores arbitrary precision. It's not a machine word, like the C# integer types (plural, or does it have only one? Either way), so it can store any integer you have RAM for. (Which means, no, Python cannot represent Graham's Number in an int. Sorry about that.) Internally, I believe CPython uses the GNU Multiprecision Library (GMP), which gives an efficient representation and operation format, scaling to infinity or thereabouts. You can go to any size of integer you like without there being any difference. There's a cost to that (even small integers are a bit slower to work with), but it's SO helpful to be able to work with arbitrarily large numbers that it's worth that cost. (Side note: In Python 2, small integers were represented by type 'int' and those too big to fit into a machine word were automatically promoted to type 'long'. Python 3 abolished 'int' and renamed 'long' to 'int', giving what you see here. I'm of the opinion that small-number arithmetic could be optimized by having small ints stored as machine words instead of as GMP objects (which could be done invisibly), but it may be that the complexity isn't worth it.) I first met arbitrary-precision arithmetic in REXX, back in the 1990s. It wasn't anything like as efficient as it is now, so for performance it was important to set the NUMERIC DIGITS setting to just what you need and no more. Today, thanks to GMP, any high level language should be able to offer the same as Python does; in fact, I'd consider infinite-precision integers to be among the fundamental and critical aspects of any modern high level language (along with object reference semantics, first-class arrays/mappings/functions/etc, native true Unicode strings, BSD socket services, and cross-platform support with a bare minimum of *ix/Win/Mac). There's just no point restricting it to a machine word, especially since "machine word" varies from machine to machine. Incidentally, if you specifically *want* wrap-around behaviour, you can perform modulo arithmetic. Store everything as unsigned, and after every operation, take the value modulo 2**64; then for display, if you need it to be signed, check if it's >= 2**63, and if so, subtract 2**64. (Or use 32, 31, and 32, or whatever word size you want.) That's a decent simulation of a simple twos-comp integer. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: No overflow in variables?
Thank you for your answers! -- https://mail.python.org/mailman/listinfo/python-list
Re: Self healthcheck
Asaf Las Wrote in message:
> On Wednesday, January 22, 2014 10:56:30 AM UTC+2, Frank Millman wrote:
>>
>> class MainObject:
>> def __init__(self, identifier):
>> self._del = delwatcher('MainObject', identifier)
>> class delwatcher:
>> def __init__(self, obj_type, identifier):
>> self.obj_type = obj_type
>> self.identifier = identifier
>> log('{}: id={} created'.format(self.obj_type, self.identifier))
>> def __del__(self):
>> log('{}: id={} deleted'.format(self.obj_type, self.identifier))
>> If you do find that an object is not being deleted, it is then
>> trial-and-error to find the problem and fix it. It is probably a circular
>> reference
>>
>> Frank Millman
>
> Thanks Frank. Good approach!
>
> One question - You could do:
> class MainObject:
> def __init__(self, identifier):
> self._del = delwatcher(self)
> then later
>
> class delwatcher:
> def __init__(self, tobject):
> self.obj_type = type(tobject)
> self.identifier = id(tobject)
> ...
>
> when creating delwatcher. Was there special reason to not to use them?
> is this because of memory is reused when objects are deleted
> and created again so same reference could be for objects created
> in different time slots?
>
I couldn't make sense of most of that. But an ID only uniquely
corresponds to an object while that object still exists. The
system may, and will, reuse iD's constantly.
--
DaveA
--
https://mail.python.org/mailman/listinfo/python-list
Re: No overflow in variables?
Thank you ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: SIngleton from __defaults__
On 1/22/14 11:37 AM, Asaf Las wrote: On Wednesday, January 22, 2014 6:18:57 PM UTC+2, Chris Angelico wrote: On Thu, Jan 23, 2014 at 3:07 AM, Asaf Las wrote: Why not simply: def get_singleton(x = SomeClass()): return x Or even: singleton = SomeClass() ? Neither of the above provides anything above the last one, except for late creation. ChrisA Actually need was to have some interface to running independent threads to give same and once created object always. For first - SomeClass's object will be created whenever there will be call to get_singleton(). No, the value for a function argument's default is computed once when the function is defined. Chris is right: get_singleton will always return the same object. For second, again it is free to create it whenever someone (thread) wish. Chris is right here, too: modules are themselves singletons, no matter how many times you import them, they are only executed once, and the same module object is provided for each import. Hmmm, use case was to create persistent counter in multithreaded app accessing single file where incrementing integer is stored. When my imagination expanded it onto multiprocessing mess i ended up using sqlite access to DB in exclusive transaction mode. But this was not pythonic :-) Asaf -- Ned Batchelder, http://nedbatchelder.com -- https://mail.python.org/mailman/listinfo/python-list
Re: Can post a code but afraid of plagiarism
On 1/22/14 12:09 PM, indar kumar wrote: On Saturday, January 18, 2014 3:21:42 PM UTC-7, indar kumar wrote: Hi, I want to show a code for review but afraid of plagiarism issues. Kindly, suggest how can I post it for review here without masking it visible for public Just one hint and I have made the design for whole code. Just stuck at this part You should collect all your thoughts and write one message, not six in 30 minutes. That's just pestering. -- Ned Batchelder, http://nedbatchelder.com -- https://mail.python.org/mailman/listinfo/python-list
awesome slugify and unicode
I thought this blog might interest some of you http://pydanny.com/awesome-slugify-human-readable-url-slugs-from-any-string.html -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence -- https://mail.python.org/mailman/listinfo/python-list
Re: Using a static library in a C extension for Python
Le 22/01/14 18:31, 8 Dihedral a écrit : Check the C source code generated by Pyrex and check cython for what u want, but I did try that out in any mobile phone or flat panel programming. Thanks a lot for your answer. I didn't use Pyrex or other tool, but wrote myself the C python wrapping, using the Python C/API documentation (http://docs.python.org/2/c-api/). I then used the distutils tool (via a setup.py file) to build my extension. While there is several function in my C code, only one needed to be accessed by python. I'll check Cython then, but is there any tweaking of the setup.py file using distutils that will help me compile the extension with the cairo lib embedded into it? -- https://mail.python.org/mailman/listinfo/python-list
Re: SIngleton from __defaults__
On Wednesday, January 22, 2014 9:18:19 PM UTC+2, Ned Batchelder wrote: > Chris is right here, too: modules are themselves singletons, no matter > how many times you import them, they are only executed once, and the > same module object is provided for each import. > > Ned Batchelder, http://nedbatchelder.com Chris, Ned, many thanks for clarification! -- https://mail.python.org/mailman/listinfo/python-list
Re: Python declarative
El miércoles, 15 de enero de 2014 18:02:08 UTC+1, Sergio Tortosa Benedito
escribió:
> Hi I'm developing a sort of language extension for writing GUI programs
>
> called guilang, right now it's written in Lua but I'm considreing Python
>
> instead (because it's more tailored to alone applications). My question
>
> it's if I can achieve this declarative-thing in python. Here's an
>
> example:
>
>
>
> Window "myWindow" {
>
> title="Hello world";
>
> Button "myButton" {
>
> label="I'm a button";
>
> onClick=exit
>
> }
>
> }
>
> print(myWindow.myButton.label)
>
>
>
> Of course it doesn't need to be 100% equal. Thanks in advance
>
>
>
> Sergio
Hi again, just wrote to announce that I'm going to rewrite guilang in Python.
Again thanks you are all awesome :).
--
https://mail.python.org/mailman/listinfo/python-list
Re: awesome slugify and unicode
On 01/22/2014 11:23 AM, Mark Lawrence wrote: I thought this blog might interest some of you http://pydanny.com/awesome-slugify-human-readable-url-slugs-from-any-string.html Thanks! -- ~Ethan~ -- https://mail.python.org/mailman/listinfo/python-list
Re: No overflow in variables?
In article , Chris Angelico wrote: > The Python integer type stores arbitrary precision. Which is not only really cool, but terribly useful for solving many Project Euler puzzles :-) -- https://mail.python.org/mailman/listinfo/python-list
Re: SIngleton from __defaults__
On Wednesday, January 22, 2014 6:18:57 PM UTC+2, Chris Angelico wrote: > On Thu, Jan 23, 2014 at 3:07 AM, Asaf Las wrote: > > is it possible to create singleton using construct below : > > > > def singleton_provider(x = [None]): > > if singleton_provider.__defaults__[0][0] == None: > > singleton_provider.__defaults__[0][0] = SomeClass() > > return singleton_provider.__defaults__[0][0] > > > > Why not simply: > def get_singleton(x = SomeClass()): > return x > Or even: > singleton = SomeClass() > ? Neither of the above provides anything above the last one, except > for late creation. > ChrisA Hi Chris Does it make sense to use former as template to make singleton from any class as below, so instead of addressing your second proposal using module name we can directly call this one supplying class candidate for singleness as argument to function? class whatever(): def __init__(self): self.one = 1 self.zero = 0 def singleton_provider(someclass, x = [None]): if singleton_provider.__defaults__[0][0] == None: singleton_provider.__defaults__[0][0] = someclass() return singleton_provider.__defaults__[0][0] print(id(singleton_provider(whatever))) Thanks Asaf -- https://mail.python.org/mailman/listinfo/python-list
Re: Python declarative
On Wednesday, January 15, 2014 7:02:08 PM UTC+2, Sergio Tortosa Benedito wrote:
> Hi I'm developing a sort of language extension for writing GUI programs
> called guilang, right now it's written in Lua but I'm considreing Python
> instead (because it's more tailored to alone applications). My question
> it's if I can achieve this declarative-thing in python. Here's an
> example:
> Window "myWindow" {
> title="Hello world";
> Button "myButton" {
> label="I'm a button";
> onClick=exit
> }
> }
> print(myWindow.myButton.label)
> Of course it doesn't need to be 100% equal. Thanks in advance
> Sergio
Hi Sergio
i am novice in python, but let me suggest you something:
it would be beneficial to use json text file to specify
your gui so composite data structure can be created using
json and then your program can construct window giving
its content will be based on simple text file?
You can add every parameter to json encoded window system
once your window construction will be using as interpreter
for that. JSON is very structured and quite presentable for
such kind of things.
What Gurus do think about this suggestion?
/Asaf
--
https://mail.python.org/mailman/listinfo/python-list
Re: Early retirement project?
[email protected] wrote: In fact, Python just becomes the last tool I (would) recommend, especially for non-ascii users. To the OP: Ignore wxjmfauth, he's our resident nutcase. -- Greg -- https://mail.python.org/mailman/listinfo/python-list
Re: Using a static library in a C extension for Python
lgabiot wrote: Le 22/01/14 18:31, 8 Dihedral a écrit : Check the C source code generated by Pyrex ... Thanks a lot for your answer. We suspect that 8 Dihedral is actually a bot, so you're *probably* wasting your time attempting to engage it in conversation. -- Greg -- https://mail.python.org/mailman/listinfo/python-list
Re: No overflow in variables?
Chris Angelico wrote: (Which means, no, Python cannot represent Graham's Number in an int. Sorry about that.) This is probably a good thing. I'm told that any computer with enough RAM to hold Graham's number would, from entropy considerations alone, have enough mass to become a black hole. -- Greg -- https://mail.python.org/mailman/listinfo/python-list
Re: SIngleton from __defaults__
On Wednesday, January 22, 2014 6:18:57 PM UTC+2, Chris Angelico wrote:
> On Thu, Jan 23, 2014 at 3:07 AM, Asaf Las wrote:
> ChrisA
and this one is about multiclass container function with
multithreading support:
import threading
def provider(cls, x = [threading.Lock(), {}]):
provider.__defaults__[0][0].acquire()
if not cls.__name__ in provider.__defaults__[0][1]:
provider.__defaults__[0][1][cls.__name__] = cls()
provider.__defaults__[0][0].release()
return provider.__defaults__[0][1][cls.__name__]
class whatever():
def __init__(self):
self.one = 1
self.zero = 0
class whatever1():
def __init__(self):
self.one = 1
self.zero = 0
print(id(provider(whatever)))
print(id(provider(whatever)))
print(id(provider(whatever1)))
print(id(provider(whatever1)))
could be there some hidden faults i missed?
/Asaf
--
https://mail.python.org/mailman/listinfo/python-list
Re: Using a static library in a C extension for Python
Hi,
Am 22.01.14 12:01, schrieb lgabiot:
Is it possible to link statically cairo to my extension, so that even if
cairo is not installed on a computer, the code will run?
I guess I would need to modify the setup.py file using distutils to
compile cairo statically into my .so file?
I've done it for a similar problem (linking HDF statically including its
dependencies zlib and libjpeg), but I did write the Makefile by hand
instead of using distutils.
First, you need to compile a static version of cairo. I.e., you probably
have got some libcairo.2.dylib or similar. This can't be used, you must
end up with a libcairo.a archive, by passing "--disable-shared
--enable-static" to the configure script. For this to work, the code
must be position-independent ("--with-pic" in autoconf). This is a no-op
on OSX, where all code is position-independent, but is important if you
plan to port it to Linux. Then, during the linking step of your
extension, you need to link against that statically compiled version of
libcairo. In a Makefile, you would pass "-L/path/to/thelibrary -lcairo"
to the compiler invocation for the linking step. I don't know distutils
enough, but maybe you can either pass "LDFLAGS" to it to do this or
directly point to that version of cairo.
Or am I completely wrong?
I'm a big fan of static linkage in that case, too.
There might be another issue with the license of the library. Cairo is
both LGPL and MPL. For LGPL, only dynamic linking is without doubt, for
MPL it seems to be accepted to link statically. It all depends on
whether you plan to pass on the binary to another person.
To circumvent this problem, it might be feasable to just install
libcairo along with you extension.
Then, the exact same version of python must be used on both computers.
Since the extension loading mechanism completely relies on the OS
dynamic linker, it is not possible to load an extension into a different
version of python than it was built for. Sadly, nobody implemented a
system like Tcl's stubs, where an array of function pointers gets passed
to the extension. This system allows to load an extension into later
versions of the host program.
Christian
--
https://mail.python.org/mailman/listinfo/python-list
Re: No overflow in variables?
On Wed, Jan 22, 2014, at 13:26, Chris Angelico wrote: > The Python integer type stores arbitrary precision. It's not a machine > word, like the C# integer types (plural, or does it have only one? C# has the usual assortment of fixed-width integer types - though by default they throw exceptions on overflow instead of wrapping around - and a BigInteger type in the library. -- https://mail.python.org/mailman/listinfo/python-list
Re: Can post a code but afraid of plagiarism
On Wed, 22 Jan 2014 00:36:17 -0800, indar kumar wrote:
> So my question is if I am giving multiple inputs(a new device say for
> example) in a loop and creating a database(dictionary) for each new
> devices for example. I want subsequent devices to save their data(values
> only not keys) to the database of each of the already existing devices.
> How can I do that? Any hint?I have been stuck here for 3 days.
Short version:
in your dict (database), instead of storing the value alone, store a list
containing each of the values.
Longer version:
Here you have a dict as database:
db = {}
Here you get a key and value, and you add then to the db:
# key is 23, value is "hello"
if 23 in db:
db[23].append("hello")
else:
db[23] = ["hello"]
Later, you can see if the key already exists:
if 23 in db:
print("Key 23 already exists")
Or you can add a second value value to the same key:
if 23 in db:
db[23].append("goodbye")
else:
db[23] = ["goodbye"]
which can be written more succinctly as:
db.setdefault(23, []).append("goodbye")
Now you can check whether the key has been seen once or twice:
if len(db[23]) == 1:
print("key 23 has been seen only once")
else:
print("key 23 has been seen twice or more times")
Does this answer your question?
--
Steven
--
https://mail.python.org/mailman/listinfo/python-list
Case insensitive exists()?
I have the need to check for a files existence against a string, but I need to do case-insensitively. I cannot efficiently get the name of every file in the dir and compare each with my string using lower(), as I have 100's of strings to check for, each in a different dir, and each dir can have 100's of files in it. Does anyone know of an efficient way to do this? There's no switch for os.path that makes exists() check case-insensitively is there? -- https://mail.python.org/mailman/listinfo/python-list
Re: Case insensitive exists()?
In article , Larry Martell wrote: > I have the need to check for a files existence against a string, but I > need to do case-insensitively. I cannot efficiently get the name of > every file in the dir and compare each with my string using lower(), > as I have 100's of strings to check for, each in a different dir, and > each dir can have 100's of files in it. I'm not quite sure what you're asking. Do you need to match the filename, or find the string in the contents of the file? I'm going to assume you're asking the former. One way or another, you need to iterate over all the directories and get all the filenames in each. The time to do that is going to totally swamp any processing you do in terms of converting to lower case and comparing to some set of strings. I would put all my strings into a set, then use os.walk() traverse the directories and for each path os.walk() returns, do "path.lower() in strings". -- https://mail.python.org/mailman/listinfo/python-list
[ANN] Oktest.py 0.13.0 - a new style testing library
Oktest 0.13.0 is released.
https://pypi.python.org/pypi/Oktest/
Oktest is a new-style testing library for Python.
## unittest
self.assertEqual(x, y)
self.assertNotEqual(x, y)
self.assertGreaterEqual(x, y)
self.assertIsInstance(obj, cls)
self.assertRegexpMatches(text, rexp)
## Oktest.py
ok (x) == y
ok (x) != y
ok (x) >= y
ok (obj).is_a(cls)
ok (text).match(rexp)
It is possible to assert WebOb/Werkzeug/Requests response object easily.
ok (response).is_response(200).json({"status":"OK"})
Install
$ easy_install oktest
User's Guide
http://www.kuwata-lab.com/oktest/oktest-py_users-guide.html
Changes
http://www.kuwata-lab.com/oktest/oktest-py_CHANGES.txt
What's New
--
* [enhance] `ok().is_response()' now supports Requests.
Example::
import requests
resp = requests.get('http://www.example.com/')
ok (resp).is_response(200, 'text/html')
* [enhance] (Experimental) Add 'oktest.web' module to help WSGI app testing.
Example::
## create WSGI application
class App(object):
def __call__(self, environ, start_response):
status = '200 OK'
headers = [('Content-Type', 'application/json')]
body= [b'''{"message":"Hello!"}'''] # bytes, not unicode
start_response(status, headers)
return body
app = App()
## test for app
import unittest
import oktest
from oktest import test, ok, subject
from oktest.web import WSGITest # !
http = WSGITest(app) # !
https = WSGITest(app, {'HTTPS': 'on'})# !
class AppTest(unittest.TestCase):
with subject('GET /'):
@test("Returns messaging JSON.")
def _(self):
resp = http.GET('/') # or http('GET', '/')
ok (resp).is_response(200).json({"message": "Hello!"})
## or
status, headers, body = http.GET('/') # or http('GET',
'/')
ok (status) == '200 OK'
ok (headers) == [('Content-Type', 'application/json')]
ok (body)== [b'''{"message":"Hello!"}''']
if __name__ == '__main__':
oktest.main()
--
regars,
makoto kuwata
--
https://mail.python.org/mailman/listinfo/python-list
Re: Case insensitive exists()?
On Wed, Jan 22, 2014 at 6:08 PM, Roy Smith wrote: > In article , > Larry Martell wrote: > >> I have the need to check for a files existence against a string, but I >> need to do case-insensitively. I cannot efficiently get the name of >> every file in the dir and compare each with my string using lower(), >> as I have 100's of strings to check for, each in a different dir, and >> each dir can have 100's of files in it. > > I'm not quite sure what you're asking. Do you need to match the > filename, or find the string in the contents of the file? I'm going to > assume you're asking the former. Yes, match the file names. e.g. if my match string is "ABC" and there's a file named "Abc" then it would be match. > One way or another, you need to iterate over all the directories and get > all the filenames in each. The time to do that is going to totally > swamp any processing you do in terms of converting to lower case and > comparing to some set of strings. > > I would put all my strings into a set, then use os.walk() traverse the > directories and for each path os.walk() returns, do "path.lower() in > strings". The issue is that I run a database query and get back rows, each with a file path (each in a different dir). And I have to check to see if that file exists. Each is a separate search with no correlation to the others. I have the full path, so I guess I'll have to do dir name on it, then a listdir then compare each item with .lower with my string .lower. It's just that the dirs have 100's and 100's of files so I'm really worried about efficiency. -- https://mail.python.org/mailman/listinfo/python-list
Re: Case insensitive exists()?
In article , Larry Martell wrote: > The issue is that I run a database query and get back rows, each with > a file path (each in a different dir). And I have to check to see if > that file exists. Each is a separate search with no correlation to the > others. I have the full path, so I guess I'll have to do dir name on > it, then a listdir then compare each item with .lower with my string > .lower. It's just that the dirs have 100's and 100's of files so I'm > really worried about efficiency. Oh, my, this is a much more complicated problem than you originally described. Is the whole path case-insensitive, or just the last component? In other words, if the search string is "/foo/bar/my_file_name", do all of these paths match? /FOO/BAR/MY_FILE_NAME /foo/bar/my_file_name /FoO/bAr/My_FiLe_NaMe Can you give some more background as to *why* you're doing this? Usually, if a system considers filenames to be case-insensitive, that's something that's handled by the operating system itself. -- https://mail.python.org/mailman/listinfo/python-list
Re: Case insensitive exists()?
On 2014-01-23 00:58, Larry Martell wrote: I have the need to check for a files existence against a string, but I need to do case-insensitively. I cannot efficiently get the name of every file in the dir and compare each with my string using lower(), as I have 100's of strings to check for, each in a different dir, and each dir can have 100's of files in it. Does anyone know of an efficient way to do this? There's no switch for os.path that makes exists() check case-insensitively is there? You don't say which OS. Filenames in Windows, for example, are already case-insensitive. Try writing it the simplest and cleanest way, without thinking about efficiency. If you discover that it really is too slow (you can always try a smaller test case initially), then you can think about how to speed it up. -- https://mail.python.org/mailman/listinfo/python-list
Re: Case insensitive exists()?
On 01/22/2014 04:58 PM, Larry Martell wrote:
I have the need to check for a files existence against a string, but I
need to do case-insensitively.
This should get you going. As it is, it will check the /entire/ string you send in even if it has path parts to it, and
there are probably other idiosyncrasies that you may want to change to match your needs.
---
def exists(filename, ci=False):
from glob import glob
search = filename
if ci:
new_search = []
for ch in filename:
new_search.append('[%s%s]' % (ch.lower(), ch.upper()))
search = ''.join(new_search)
found = glob(search)
return bool(found)
---
--
~Ethan~
--
https://mail.python.org/mailman/listinfo/python-list
Re: Using a static library in a C extension for Python
Le 22/01/14 23:09, Gregory Ewing a écrit : We suspect that 8 Dihedral is actually a bot, so you're *probably* wasting your time attempting to engage it in conversation. Thanks, so that will be my first real experience of the Turing test!!! -- https://mail.python.org/mailman/listinfo/python-list
Re: Using a static library in a C extension for Python
thanks a lot for your very precise answer! shortly, as I'm running out of time right now: I've got here a lot of informations, so I'll dig in the directions you gave me. It will be a good compiling exercise... (I'm really new at all this). -- https://mail.python.org/mailman/listinfo/python-list
Re: Case insensitive exists()?
On Thu, Jan 23, 2014 at 12:27 PM, MRAB wrote: > On 2014-01-23 00:58, Larry Martell wrote: >> >> I have the need to check for a files existence against a string, but I >> need to do case-insensitively. I cannot efficiently get the name of >> every file in the dir and compare each with my string using lower(), >> as I have 100's of strings to check for, each in a different dir, and >> each dir can have 100's of files in it. Does anyone know of an >> efficient way to do this? There's no switch for os.path that makes >> exists() check case-insensitively is there? >> > You don't say which OS. Filenames in Windows, for example, are already > case-insensitive. There are weird use-cases for case insensitive filename matching on a case sensitive file system. (For instance, a program that parses a playlist file created on Windows. I did that a while ago - had to map "Foobar.MID" to "FooBar.mid", matching case insensitively and retrieving the actual case used on the FS.) A good data structure is probably all you need. As Roy suggests, iterate once over the directories - for instance, create a dict mapping the .lower() of the filename to the original. Of course, then you have to worry about collisions... though you may be able to guarantee that they can't happen (in the above case, I was looking through a directory tree that was unzipped straight from the Windows collection, ergo no two filenames could differ only in case). Or maybe you *think* you can guarantee it, but due to a bug you can't. (Ever had a USB stick, formatted NTFS, with two files differing only in case? Windows XP behaves... oddly. And rather amusingly.) ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: Python declarative
On Thu, Jan 23, 2014 at 8:16 AM, Asaf Las wrote: > i am novice in python, but let me suggest you something: > it would be beneficial to use json text file to specify > your gui so composite data structure can be created using > json and then your program can construct window giving > its content will be based on simple text file? > You can add every parameter to json encoded window system > once your window construction will be using as interpreter > for that. JSON is very structured and quite presentable for > such kind of things. > > What Gurus do think about this suggestion? JSON is better than XML for that, but in my opinion, both are unnecessary. Python code is easy to edit. (See [1] for more on Python and XML.) When you're writing compiled code, it makes good sense to drop out of code and use a simple text file when you can; but when your code *is* a simple text file, why go to the effort of making a JSON-based window builder? (Unless you already have one. GladeXML may well be exactly what you want, in which case, go ahead and use it. But personally, I don't.) JSON is a fantastic format for transmitting complex objects around the internet; it's compact (unlike XML), readable in many languages (like XML), easily readable by humans (UNLIKE XML!), and can represent all the most common data structures (subtly, XML can't technically do this). It's superb at what it does... but it doesn't do Python GUIs. For those, use Python itself. ChrisA [1] http://dirtsimple.org/2004/12/python-is-not-java.html -- https://mail.python.org/mailman/listinfo/python-list
Re: Using a static library in a C extension for Python
On Thu, Jan 23, 2014 at 10:00 AM, Christian Gollwitzer wrote: > There might be another issue with the license of the library. Cairo is both > LGPL and MPL. For LGPL, only dynamic linking is without doubt, for MPL it > seems to be accepted to link statically. It all depends on whether you plan > to pass on the binary to another person. > To circumvent this problem, it might be feasable to just install libcairo > along with you extension. > > Then, the exact same version of python must be used on both computers. Since > the extension loading mechanism completely relies on the OS dynamic linker, > it is not possible to load an extension into a different version of python > than it was built for. If you can tie in with your OS's package manager, that would solve all of these problems. You get the OS-supplied Pythom and the OS-supplied libcairo; grabbing libcairo-dev (or, on my Debian system, libcairo2-dev to go with libcairo2) gets you what you need to build your extension; you then might even package your extension the same way, and then simply declare dependencies. Can save a HUGE amount of trouble. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
problem with sqlite3: cannot use < in a SQL query with (?)
Hello,
I'm building an application using a simple sqlite3 database.
At some point, I need to select rows (more precisely some fields in
rows) that have the following property: their field max_level (an INT),
should not exceed a value stored in a variable called threshold, where
an int is stored (value 2).
(threshold needs to be set by the user, so I cannot hard code a value
there).
My database already exist on my drive (and of course the sqlite3 module
is imported)
I do the following:
>>>conn = sqlite3.connect(mydb) # open the database
that's OK
>>>cursor = conn.execute("SELECT filename, filepath FROM files WHERE
max_level<(?)", threshold)
that doesn't work (throw an exception)
if I do:
>>>cursor = conn.execute("SELECT filename, filepath FROM files WHERE
max_level<2)")
it works...
I did similar operations on UPDATE instead of SELECT, and it works there.
Maybe my mind is fried right now, but I can't figure out the solution...
best regards.
--
https://mail.python.org/mailman/listinfo/python-list
Re: problem with sqlite3: cannot use < in a SQL query with (?)
I did similar operations on UPDATE instead of SELECT, and it works there. Maybe my mind is fried right now, but I can't figure out the solution... so maybe I should rename my post: cannot use =, < with (?) in SELECT WHERE query ? -- https://mail.python.org/mailman/listinfo/python-list
Re: problem with sqlite3: cannot use < in a SQL query with (?)
On Thu, Jan 23, 2014 at 1:32 PM, lgabiot wrote:
cursor = conn.execute("SELECT filename, filepath FROM files WHERE
max_level<(?)", threshold)
> that doesn't work (throw an exception)
What exception, exactly? Was it telling you that an integer is not
iterable, perhaps? If so, check your docs for conn.execute(). If not,
can you post the exact exception, please?
ChrisA
--
https://mail.python.org/mailman/listinfo/python-list
Re: problem with sqlite3: cannot use < in a SQL query with (?)
On 1/22/2014 9:32 PM, lgabiot wrote:
Hello,
I'm building an application using a simple sqlite3 database.
At some point, I need to select rows (more precisely some fields in
rows) that have the following property: their field max_level (an INT),
should not exceed a value stored in a variable called threshold, where
an int is stored (value 2).
(threshold needs to be set by the user, so I cannot hard code a value
there).
My database already exist on my drive (and of course the sqlite3
module is imported)
I do the following:
>>>conn = sqlite3.connect(mydb) # open the database
that's OK
>>>cursor = conn.execute("SELECT filename, filepath FROM files WHERE
max_level<(?)", threshold)
that doesn't work (throw an exception)
PLEASE POST THE TRACEBACK!
Also get rid of the() around the ?.
if I do:
>>>cursor = conn.execute("SELECT filename, filepath FROM files WHERE
max_level<2)")
it works...
I did similar operations on UPDATE instead of SELECT, and it works there.
Maybe my mind is fried right now, but I can't figure out the solution...
best regards.
--
https://mail.python.org/mailman/listinfo/python-list
Re: problem with sqlite3: cannot use < in a SQL query with (?)
On 1/22/2014 9:32 PM, lgabiot wrote:
Hello,
I'm building an application using a simple sqlite3 database.
At some point, I need to select rows (more precisely some fields in
rows) that have the following property: their field max_level (an INT),
should not exceed a value stored in a variable called threshold, where
an int is stored (value 2).
(threshold needs to be set by the user, so I cannot hard code a value
there).
My database already exist on my drive (and of course the sqlite3
module is imported)
I do the following:
>>>conn = sqlite3.connect(mydb) # open the database
that's OK
>>>cursor = conn.execute("SELECT filename, filepath FROM files WHERE
max_level<(?)", threshold)
that doesn't work (throw an exception)
if I do:
>>>cursor = conn.execute("SELECT filename, filepath FROM files WHERE
max_level<2)")
it works...
I did similar operations on UPDATE instead of SELECT, and it works there.
SO SHOW US THE UPDATE. "Similar" does not help.
Maybe my mind is fried right now, but I can't figure out the solution...
best regards.
--
https://mail.python.org/mailman/listinfo/python-list
Re: problem with sqlite3: cannot use < in a SQL query with (?)
On 2014-01-23 03:32, lgabiot wrote:
> >>>cursor = conn.execute("SELECT filename, filepath FROM files
> >>>WHERE
> max_level<(?)", threshold)
> that doesn't work (throw an exception)
That last argument should be a tuple, so unless "threshold"
is a tuple, you would want to make it
sql = "SELECT ... WHERE max_level < ?"
cursor = conn.execute(sql, (threshold,))
-tkc
--
https://mail.python.org/mailman/listinfo/python-list
Re: Python declarative
On 1/22/2014 9:29 PM, Chris Angelico wrote: On Thu, Jan 23, 2014 at 8:16 AM, Asaf Las wrote: i am novice in python, but let me suggest you something: it would be beneficial to use json text file to specify your gui so composite data structure can be created using json and then your program can construct window giving its content will be based on simple text file? You can add every parameter to json encoded window system once your window construction will be using as interpreter for that. JSON is very structured and quite presentable for such kind of things. JSON is better than XML for that, but in my opinion, both are unnecessary. Python code is easy to edit. (See [1] for more on Python and XML.) When you're writing compiled code, it makes good sense to drop out of code and use a simple text file when you can; but when your code *is* a simple text file, why go to the effort of making a JSON-based window builder? (Unless you already have one. GladeXML may well be exactly what you want, in which case, go ahead and use it. But personally, I don't.) JSON is a fantastic format for transmitting complex objects around the internet; it's compact (unlike XML), readable in many languages (like XML), easily readable by humans (UNLIKE XML!), and can represent all the most common data structures (subtly, XML can't technically do this). It's superb at what it does... but it doesn't do Python GUIs. For those, use Python itself. I would only use JSON if I wanted a declaration format that was independent of implementation languages, that could be read and turned into application objects by as least two languages. -- Terry Jan Reedy -- https://mail.python.org/mailman/listinfo/python-list
Re: Case insensitive exists()?
On Wed, Jan 22, 2014 at 6:27 PM, Roy Smith wrote: > In article , > Larry Martell wrote: > >> The issue is that I run a database query and get back rows, each with >> a file path (each in a different dir). And I have to check to see if >> that file exists. Each is a separate search with no correlation to the >> others. I have the full path, so I guess I'll have to do dir name on >> it, then a listdir then compare each item with .lower with my string >> .lower. It's just that the dirs have 100's and 100's of files so I'm >> really worried about efficiency. > > Oh, my, this is a much more complicated problem than you originally > described. I try not to bother folks with simple problems ;-) > Is the whole path case-insensitive, or just the last component? In > other words, if the search string is "/foo/bar/my_file_name", do all of > these paths match? > > /FOO/BAR/MY_FILE_NAME > /foo/bar/my_file_name > /FoO/bAr/My_FiLe_NaMe Just the file name (the basename). > Can you give some more background as to *why* you're doing this? > Usually, if a system considers filenames to be case-insensitive, that's > something that's handled by the operating system itself. I can't say why it's happening. This is a big complicated system with lots of parts. There's some program that ftp's image files from an electron microscope and stores them on the file system with crazy names like: 2O_TOPO_1_2O_2UM_FOV_M1_FX-2_FY4_DX0_DY0_DZ0_SDX10_SDY14_SDZ0_RR1_TR1_Ver1.jpg And something (perhaps the same program, perhaps a different one) records this is a database. In some cases the name recorded in the db has different cases in some characters then how it was stored in the db, e.g.: 2O_TOPO_1_2O_2UM_Fov_M1_FX-2_FY4_DX0_DY0_DZ0_SDX10_SDY14_SDZ0_RR1_TR1_Ver1.jpg These only differ in "FOV" vs. "Fov" but that is just one example. I am writing something that is part of a django app, that based on some web entry from the user, I run a query, get back a list of files and have to go receive them and serve them up back to the browser. My script is all done and seem to be working, then today I was informed it was not serving up all the images. Debugging revealed that it was this case issue - I was matching with exists(). As I've said, coding a solution is easy, but I fear it will be too slow. Speed is important in web apps - users have high expectations. Guess I'll just have to try it and see. -- https://mail.python.org/mailman/listinfo/python-list
Re: Case insensitive exists()?
On Wed, Jan 22, 2014 at 6:27 PM, MRAB wrote: > On 2014-01-23 00:58, Larry Martell wrote: >> >> I have the need to check for a files existence against a string, but I >> need to do case-insensitively. I cannot efficiently get the name of >> every file in the dir and compare each with my string using lower(), >> as I have 100's of strings to check for, each in a different dir, and >> each dir can have 100's of files in it. Does anyone know of an >> efficient way to do this? There's no switch for os.path that makes >> exists() check case-insensitively is there? >> > You don't say which OS. Filenames in Windows, for example, are already > case-insensitive. Linux. > Try writing it the simplest and cleanest way, without thinking about > efficiency. If you discover that it really is too slow (you can always > try a smaller test case initially), then you can think about how to > speed it up. Yes, that's my plan. -- https://mail.python.org/mailman/listinfo/python-list
Re: Case insensitive exists()?
On Thu, Jan 23, 2014 at 3:24 PM, Larry Martell wrote: > I am writing something that is part of a django app, that based on > some web entry from the user, I run a query, get back a list of files > and have to go receive them and serve them up back to the browser. My > script is all done and seem to be working, then today I was informed > it was not serving up all the images. Debugging revealed that it was > this case issue - I was matching with exists(). As I've said, coding a > solution is easy, but I fear it will be too slow. Speed is important > in web apps - users have high expectations. Guess I'll just have to > try it and see. Would it be a problem to rename all the files? Then you could simply lower() the input name and it'll be correct. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
sqlite3 docbug (was problem with sqlite3)
On Thursday, January 23, 2014 8:35:58 AM UTC+5:30, Tim Chase wrote:
> On 2014-01-23 03:32, lgabiot wrote:
> > >>>cursor = conn.execute("SELECT filename, filepath FROM files
> > >>>WHERE
> > max_level<(?)", threshold)
> > that doesn't work (throw an exception)
> That last argument should be a tuple, so unless "threshold"
> is a tuple, you would want to make it
> sql = "SELECT ... WHERE max_level < ?"
> cursor = conn.execute(sql, (threshold,))
Seeing this is becoming a faq I looked at the docs to see if the tuple second
argument could do with some more emphasis
I think it sure could; see
http://docs.python.org/2/library/sqlite3.html#sqlite3.Cursor
The builtin connection.execute is even less helpful
--
https://mail.python.org/mailman/listinfo/python-list
Re: sqlite3 docbug (was problem with sqlite3)
On Thursday, January 23, 2014 10:03:43 AM UTC+5:30, Rustom Mody wrote: > The builtin connection.execute is even less helpful I meant help(conn.execute) -- https://mail.python.org/mailman/listinfo/python-list
Re: sqlite3 docbug (was problem with sqlite3)
On Thu, Jan 23, 2014 at 3:33 PM, Rustom Mody wrote:
> On Thursday, January 23, 2014 8:35:58 AM UTC+5:30, Tim Chase wrote:
>> On 2014-01-23 03:32, lgabiot wrote:
>> > >>>cursor = conn.execute("SELECT filename, filepath FROM files
>> > >>>WHERE
>> > max_level<(?)", threshold)
>> > that doesn't work (throw an exception)
>
>> That last argument should be a tuple, so unless "threshold"
>> is a tuple, you would want to make it
>
>> sql = "SELECT ... WHERE max_level < ?"
>> cursor = conn.execute(sql, (threshold,))
>
> Seeing this is becoming a faq I looked at the docs to see if the tuple second
> argument could do with some more emphasis
>
> I think it sure could; see
> http://docs.python.org/2/library/sqlite3.html#sqlite3.Cursor
>
> The builtin connection.execute is even less helpful
I think it's fairly clear from the example that it has to be either a
tuple or a dict. Looks fine to me. But I'm sure that, if you come up
with better wording, a tracker issue would get the attention it
deserves.
ChrisA
--
https://mail.python.org/mailman/listinfo/python-list
Re: Diving in to Python - Best resources?
If you are already a Perl programmer, this link could be useful! https://wiki.python.org/moin/PerlPhrasebook A -- https://mail.python.org/mailman/listinfo/python-list
Re: Self healthcheck
"Asaf Las" wrote in message news:[email protected]... > On Wednesday, January 22, 2014 10:56:30 AM UTC+2, Frank Millman wrote: >> >> class MainObject: >> def __init__(self, identifier): >> self._del = delwatcher('MainObject', identifier) >> class delwatcher: >> def __init__(self, obj_type, identifier): >> self.obj_type = obj_type >> self.identifier = identifier >> log('{}: id={} created'.format(self.obj_type, self.identifier)) >> def __del__(self): >> log('{}: id={} deleted'.format(self.obj_type, self.identifier)) >> If you do find that an object is not being deleted, it is then >> trial-and-error to find the problem and fix it. It is probably a circular >> reference >> >> Frank Millman > > Thanks Frank. Good approach! > > One question - You could do: > class MainObject: >def __init__(self, identifier): > self._del = delwatcher(self) > then later > > class delwatcher: >def __init__(self, tobject): >self.obj_type = type(tobject) >self.identifier = id(tobject) >... > > when creating delwatcher. Was there special reason to not to use them? > is this because of memory is reused when objects are deleted > and created again so same reference could be for objects created > in different time slots? > I read Dave's reply, and he is correct in saying that id's are frequently re-used in python. However, in this particular case, I think you are right, it is safe to use the id to identify the object. An id can only be re-used if the original object is deleted, and that is the whole point of this exercise. We expect to see the id come up in a 'created' message, and then the same id appear in a 'deleted' message. If this happens, we are not concerned if the same id reappears in a subsequent 'created' message. Frank -- https://mail.python.org/mailman/listinfo/python-list
Re: sqlite3 docbug (was problem with sqlite3)
On Thursday, January 23, 2014 10:11:42 AM UTC+5:30, Chris Angelico wrote: > I think it's fairly clear from the example that it has to be either a > tuple or a dict. Looks fine to me. yes 'from the example' and only from there! -- https://mail.python.org/mailman/listinfo/python-list
Re: sqlite3 docbug (was problem with sqlite3)
On Thu, Jan 23, 2014 at 4:35 PM, Rustom Mody wrote: > On Thursday, January 23, 2014 10:11:42 AM UTC+5:30, Chris Angelico wrote: >> I think it's fairly clear from the example that it has to be either a >> tuple or a dict. Looks fine to me. > > yes 'from the example' and only from there! The fact that there's only one parameter that's supposed to handle all of that also strongly suggests that it's a tuple. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: sqlite3 docbug (was problem with sqlite3)
On Thursday, January 23, 2014 6:41:42 AM UTC+2, Chris Angelico wrote:
> On Thu, Jan 23, 2014 at 3:33 PM, Rustom Mody wrote:
> I think it's fairly clear from the example that it has to be either a
> tuple or a dict. Looks fine to me. But I'm sure that, if you come up
> with better wording, a tracker issue would get the attention it
> deserves.
> ChrisA
It looks like tuple, but i could be wrong:
from python-3.3.3.tar.bz2\Python-3.3.3\Modules\_sqlite\cursor.c
PyObject* _pysqlite_query_execute(pysqlite_Cursor* self, int multiple,
PyObject* args)
{
...
if (multiple) {
/* executemany() */
if (!PyArg_ParseTuple(args, "OO", &operation, &second_argument)) {
goto error;
}
/Asaf
--
https://mail.python.org/mailman/listinfo/python-list
Re: awesome slugify and unicode
Le mercredi 22 janvier 2014 20:23:55 UTC+1, Mark Lawrence a écrit : > I thought this blog might interest some of you > > http://pydanny.com/awesome-slugify-human-readable-url-slugs-from-any-string.html > > > > -- > > My fellow Pythonistas, ask not what our language can do for you, ask > > what you can do for our language. > > > > This is not "unicode", only string manipulations. The same work could be done with, let say, cp1252. The difference lies in the repertoires of characters to be handled. A better way is to work with normalization() and/or with methods like .translate() with dedicated tables; the hard task being the creation of these tables. Shortly, very naive. jmf -- https://mail.python.org/mailman/listinfo/python-list
Re: sqlite3 docbug (was problem with sqlite3)
Thanks to all,
that was indeed the tuple issue!
the correct code is:
>>>cursor = conn.execute("SELECT filename, filepath FROM files WHERE
max_level
as was pointed out by many.
Sorry for missing such a silly point (well, a comma in fact). I'll learn
to read more seriously the doc, but I was really confused (I spent more
than one hour trying so many combinations, reading the doc, books I
have, etc... before posting, and I was stuck)
but the basis for my blindness was more a lack of grasp of the
fundamentals: how to declare a one element tuple.
Because I tried to write (threshold) being convinced it was a tuple...
I need to remember at all times: https://wiki.python.org/moin/TupleSyntax
best regards.
--
https://mail.python.org/mailman/listinfo/python-list
Re: Using a static library in a C extension for Python
Le 23/01/14 03:33, Chris Angelico a écrit : On Thu, Jan 23, 2014 at 10:00 AM, Christian Gollwitzer wrote: There might be another issue with the license of the library. Cairo is both LGPL and MPL. For LGPL, only dynamic linking is without doubt, for MPL it seems to be accepted to link statically. It all depends on whether you plan to pass on the binary to another person. To circumvent this problem, it might be feasable to just install libcairo along with you extension. Then, the exact same version of python must be used on both computers. Since the extension loading mechanism completely relies on the OS dynamic linker, it is not possible to load an extension into a different version of python than it was built for. If you can tie in with your OS's package manager, that would solve all of these problems. You get the OS-supplied Pythom and the OS-supplied libcairo; grabbing libcairo-dev (or, on my Debian system, libcairo2-dev to go with libcairo2) gets you what you need to build your extension; you then might even package your extension the same way, and then simply declare dependencies. Can save a HUGE amount of trouble. ChrisA thank you very much for your answer, I'll work on your informations. -- https://mail.python.org/mailman/listinfo/python-list
Re: sqlite3 docbug (was problem with sqlite3)
On Thu, Jan 23, 2014 at 6:18 PM, Asaf Las wrote:
> if (!PyArg_ParseTuple(args, "OO", &operation, &second_argument)) {
> goto error;
> }
That part just asks for "any object" as the second argument. Also,
that part is handling executemany(). Later on, the execute() handler
looks for an optional second arg, and then looks for an iterator from
it.
But as a general rule, I'd advise reading the docs rather than the
source, unless you're trying to figure out whether some other iterable
will work. For the most part, just follow the examples and use a
tuple.
ChrisA
--
https://mail.python.org/mailman/listinfo/python-list
Re: Can post a code but afraid of plagiarism
On Saturday, January 18, 2014 3:21:42 PM UTC-7, indar kumar wrote:
> Hi,
>
>
>
> I want to show a code for review but afraid of plagiarism issues. Kindly,
> suggest how can I post it for review here without masking it visible for
> public
Thanks for kind help.
I have following nested dictionary
hosts={'PC2': ['02:02:02:02:02:02', '192.168.0.2', '200', {'192.168.0.2':
('02:02:02:02:02:02', 1390461798.531)}], 'PC1': ['01:01:01:01:01:01',
'192.168.0.1', '200', {'192.168.0.2': ('02:02:02:02:02:02', 1390461798.531),
'192.168.0.1': ('01:01:01:01:01:01', 1390461787.78)}]}
How can I print a particular tuple from this table?
What I am trying to do is
input1=raw_input("Please enter id of host and IP that you want to be resolved")
z=input1.split()
print("PC3 resolved"+' '+z[1]+' to'+hosts[z[0]][3] z[1])
#z[1] is ip entered and [z[0]][3] z[1] is the particular location of value(MAC)
associated with IP that I want to print.
But failed to do so. How can I print that. Please guide
--
https://mail.python.org/mailman/listinfo/python-list
Re: Case insensitive exists()?
On Wed, 22 Jan 2014 18:18:32 -0700, Larry Martell wrote: > The issue is that I run a database query and get back rows, each with > a file path (each in a different dir). And I have to check to see if > that file exists. Each is a separate search with no correlation to the > others. I have the full path, so I guess I'll have to do dir name on > it, then a listdir then compare each item with .lower with my string > .lower. It's just that the dirs have 100's and 100's of files so I'm > really worried about efficiency. Okay, so it's not Python, and I have the benefit of having read all of the other answers, but what about calling "locate" [0] with the "-i" flag? or writing some sort of Python/ctypes wrapper around the part of locate that searches the database? Dan [0] http://savannah.gnu.org/projects/findutils/ -- https://mail.python.org/mailman/listinfo/python-list
