Re: Cross platform mutex to prevent script running more than instance?
What about using flock()? I don't know if it works on Windows, but it works really well for Unix/Linux systems. I typically create a log file in a known location using any atomic method that doesn't replace/overwrite a file, and flock() it for the duration of the script. Thanks, Cem Karan On Mon, Sep 3, 2018, 11:39 PM Cameron Simpson wrote: > On 03Sep2018 07:45, Malcolm Greene wrote: > >Use case: Want to prevent 2+ instances of a script from running ... > >ideally in a cross platform manner. I've been researching this topic and > >am surprised how complicated this capability appears to be and how the > >diverse the solution set is. I've seen solutions ranging from using > >directories, named temporary files, named sockets/pipes, etc. Is there > >any consensus on best practice here? > > I like os.mkdir of a known directory name. This tends to be atomic and > forbidden when the name already exists, on all UNIX platforms, over remote > filesystems. And, I expect, likewise on Windows. > > All the other modes like opening files O_EXCL etc tend to be platform > specific > and not reliable over network filesystems. > > And pid based approaches don't work cross machine, if that is an issue. > > Cheers, > Cameron Simpson > -- > https://mail.python.org/mailman/listinfo/python-list > -- https://mail.python.org/mailman/listinfo/python-list
Any SML coders able to translate this to Python?
I have this snippet of SML code which I'm trying to translate to Python: fun isqrt n = if n=0 then 0 else let val r = isqrt (n/4) in if n < (2*r+1)^2 then 2*r else 2*r+1 end I've tried reading up on SML and can't make heads or tails of the "let...in...end" construct. The best I've come up with is this: def isqrt(n): if n == 0: return 0 else: r = isqrt(n/4) if n < (2*r+1)**2: return 2*r else: return 2*r+1 but I don't understand the let ... in part so I'm not sure if I'm doing it right. -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere." -- Jon Ronson -- https://mail.python.org/mailman/listinfo/python-list
Re: Any SML coders able to translate this to Python?
On Tue, 4 Sep 2018 at 13:31, Steven D'Aprano wrote: > > I have this snippet of SML code which I'm trying to translate to Python: > > fun isqrt n = if n=0 then 0 > else let val r = isqrt (n/4) > in > if n < (2*r+1)^2 then 2*r > else 2*r+1 > end > > > I've tried reading up on SML and can't make heads or tails of the > "let...in...end" construct. > > > The best I've come up with is this: > > def isqrt(n): > if n == 0: > return 0 > else: > r = isqrt(n/4) > if n < (2*r+1)**2: > return 2*r > else: > return 2*r+1 > > but I don't understand the let ... in part so I'm not sure if I'm doing > it right. I've not used SML much, but what you have looks right. let ... in is basically a local binding "let x = 12 in x+2" is saying "the value of x+2 with x set to 12". As I'm sure you realise (but I'll add it here for the sake of any newcomers who read this), the recursive approach is not natural (or efficient) in Python, whereas it's the natural approach in functional languages like SML. In Python an iterative solution would be better. Paul -- https://mail.python.org/mailman/listinfo/python-list
Re: Any SML coders able to translate this to Python?
Steven D'Aprano : > I have this snippet of SML code which I'm trying to translate to Python: > > fun isqrt n = if n=0 then 0 > else let val r = isqrt (n/4) > in > if n < (2*r+1)^2 then 2*r > else 2*r+1 > end > > > I've tried reading up on SML and can't make heads or tails of the > "let...in...end" construct. > > > The best I've come up with is this: > > def isqrt(n): > if n == 0: > return 0 > else: > r = isqrt(n/4) > if n < (2*r+1)**2: > return 2*r > else: > return 2*r+1 > > but I don't understand the let ... in part so I'm not sure if I'm doing > it right. You must make sure "r" doesn't leak outside its syntactic context so: def isqrt(n): if n == 0: return 0 else: def f2398478957(): r = isqrt(n//4) if n < (2*r+1)**2: return 2*r else: return 2*r+1 return f2398478957() (Also use // instead of /: isqrt = integer square root.) Marko -- https://mail.python.org/mailman/listinfo/python-list
Re: Verifying the integrity/lineage of a file
On 2018-09-01, Peter Pearson wrote: > Writing your own crypto software is fraught with peril, and that > includes using existing libraries. Writing your own crypto software isn't a problem, and it can be very educational. Just don't _use_ your own crypto software. Howerver, the set of people who write software without intending to use it is pretty small... -- Grant Edwards grant.b.edwardsYow! ... the MYSTERIANS are at in here with my CORDUROY gmail.comSOAP DISH!! -- https://mail.python.org/mailman/listinfo/python-list
Re: Anaconda with Python 3.7
On 03/09/2018 10:49, Thomas Jollans wrote: On 2018-09-03 11:38, gvim wrote: Anyone have any idea when Anaconda might ship a version compatible with Python 3.7. I sent them 2 emails but no reply. gvim You can install Python 3.7 in a conda environment right now. Most packages (certainly all the ones I use) appear to be available for Python 3.7 at least on Windows and Linux already. That's not the same as a specific Python 3.7 distribution. Why are they so tight-lipped about it? I mean it's been a couple of months now. Do they usually take so long? gvim -- https://mail.python.org/mailman/listinfo/python-list
problem with json.dumps / complexjson.loads in python 3.4 virtualenv
Greetings, I have an error in a python application that I installed. I already opened an issue about it on the application page at github, but I would also greatly appreciate any help to (at least) better debug the problem, because I urgently need to use that program. Details: I need to run the python client for the shaarli bookmarks manager, whose home page is https://github.com/shaarli/python-shaarli-client, on a Centos release 7.5 x86_64 server. Since that client requires python >= 3.4, and I do not want to move the whole server to that version, I created a virtualenv following the instructions at https://github.com/shaarli/python-shaarli-client/blob/master/docs/user/installation.rst When I try to run it, I get the error messages that I already reported in full at https://github.com/shaarli/python-shaarli-client/issues/33 as far as I can understand after some searching, it **may** be the problem described at https://mcgrattan.org/2017/01/24/ordered-json-in-python-with-requests/ but I honestly don't know enough python, to go further without some help/pointers. TIA, Marco -- http://mfioretti.com -- https://mail.python.org/mailman/listinfo/python-list
Re: Cross platform mutex to prevent script running more than instance?
On 09/04/2018 05:35 AM, Cameron Simpson wrote: On 03Sep2018 07:45, Malcolm Greene wrote: Use case: Want to prevent 2+ instances of a script from running ... ideally in a cross platform manner. I've been researching this topic and am surprised how complicated this capability appears to be and how the diverse the solution set is. I've seen solutions ranging from using directories, named temporary files, named sockets/pipes, etc. Is there any consensus on best practice here? I like os.mkdir of a known directory name. This tends to be atomic and forbidden when the name already exists, on all UNIX platforms, over remote filesystems. And, I expect, likewise on Windows. The trouble with a simple lock file (or directory) is of course that it can't recover from the program being killed or from program or system crashes without manual intervention. For some use cases that's fine, for others it's a problem. All the other modes like opening files O_EXCL etc tend to be platform specific and not reliable over network filesystems. And pid based approaches don't work cross machine, if that is an issue. I think a PID file is the traditional approach for *nix daemons, but as you say, it does have its own drawbacks. -- Thomas -- https://mail.python.org/mailman/listinfo/python-list
Hi I'm trying to get live data from stock using python , is it possible?
Hi , for example: I want to know if AAPL is more than value 300 and if it does I want it to send to me mail with gmail :) . thanks for the help.. -- https://mail.python.org/mailman/listinfo/python-list
Re: Hi I'm trying to get live data from stock using python , is it possible?
On Tuesday, September 4, 2018 at 7:21:31 PM UTC+3, [email protected] wrote: > Hi , > for example: > I want to know if AAPL is more than value 300 and if it does I want it to > send to me mail with gmail :) . thanks for the help.. im using python 2.7 -- https://mail.python.org/mailman/listinfo/python-list
Re: Pass a list of values as options to 3 dropdown menus
On Sun, 2 Sep 2018 13:40:18 -0700 (PDT), Nick Berg wrote: > how can i be able to store a list of values to drop-down menu and then > grab the value that the user selects? > > ** > name = month = year = '' > > # populate names, months, years > names.add( '' ) > months = ( '==', 'Ιανουάριο ... > years = ( '=', 2010, 2011, 2012, 2 ... > > > pdata = pdata + ''' > Επιλεκτική Αναζήτηση: > > > %s > > > > %s > > > > %s > > value="<Αναζήτηση>"> > > ''' % ( url_for( 'seek', name=name, month=month, year=year ), name, name, > month, month, year, year ) > ** I can't tell whether this is an HTML question or a Python question. If you can reduce it to a Python question, perhaps I can help. -- To email me, substitute nowhere->runbox, invalid->com. -- https://mail.python.org/mailman/listinfo/python-list
CURSES WINDOWS
Hello All, can anyone please let me know what's the path to port linux python curses program to Windows? Thanks -- https://mail.python.org/mailman/listinfo/python-list
Re: Hi I'm trying to get live data from stock using python , is it possible?
On 2018-09-04 18:22, [email protected] wrote: > On Tuesday, September 4, 2018 at 7:21:31 PM UTC+3, [email protected] wrote: >> Hi , >> for example: >> I want to know if AAPL is more than value 300 and if it does I want it to >> send to me mail with gmail :) . thanks for the help.. Of course it's possible. The standard library includes facilities modules for interacting with web services, modules for writing emails, and everything else you'll need. > > im using python 2.7 > Please use Python 3, especially if you're new to Python. Python 2.7 is woefully out of date. -- https://mail.python.org/mailman/listinfo/python-list
Re: Hi I'm trying to get live data from stock using python , is it possible?
> I want to know if AAPL is more than value 300 and if it does I want it to > send to me mail with gmail :) . thanks for the help.. Try searching pypi.org for "finance", then scroll through the many returned packages. A few show how to get stock data from Yahoo! or Google. Skip -- https://mail.python.org/mailman/listinfo/python-list
Re: Hi I'm trying to get live data from stock using python , is it possible?
On 09/04/2018 10:21 AM, [email protected] wrote: > Hi , > for example: > I want to know if AAPL is more than value 300 and if it does I want it to > send to me mail with gmail :) . thanks for the help.. > Yes it's definitely possible! Hop on Google and do some searches; you're bound to find some articles on the subject, possibly some demo code, and probably some Python libraries to automate the process. Google search terms you'll want to try include things like "python stock price email." -- https://mail.python.org/mailman/listinfo/python-list
Re: Pass a list of values as options to 3 dropdown menus
On 9/4/2018 1:03 PM, Peter Pearson wrote: On Sun, 2 Sep 2018 13:40:18 -0700 (PDT), Nick Berg wrote: how can i be able to store a list of values to drop-down menu and then grab the value that the user selects? In a python program, use one of the gui packages. Tkinter usually comes with python and can handle this easily with a Listbox or ttk.Combobox. -- Terry Jan Reedy -- https://mail.python.org/mailman/listinfo/python-list
Re: Any SML coders able to translate this to Python?
On 2018-09-04 14:26, Steven D'Aprano wrote: > I have this snippet of SML code which I'm trying to translate to Python: > > fun isqrt n = if n=0 then 0 > else let val r = isqrt (n/4) > in > if n < (2*r+1)^2 then 2*r > else 2*r+1 > end > > > I've tried reading up on SML and can't make heads or tails of the > "let...in...end" construct. I don't know SML specifically, but my guess would be that let X = Y in A end means "A, evaluated in a local scope where X refers to Y". Reasoning: often (e.g. in JavaScript), 'let' sets something in a local scope, and I think Haskell has a construct like this? It's been a while since I played around with Haskell though... In an as-direct-as-possible Python translation, (lambda X=Y: A)() So, isqrt = (lambda n: 0 if n == 0 else (lambda r=isqrt(n//4): 2*r if n < (2*r+1)**2 else 2*r+1)()) This is obviously the same as your multi-expression function, with the addition of the integer division as suggested by Marko. Cheers, Thomas > > The best I've come up with is this: > > def isqrt(n): > if n == 0: > return 0 > else: > r = isqrt(n/4) > if n < (2*r+1)**2: > return 2*r > else: > return 2*r+1 > > but I don't understand the let ... in part so I'm not sure if I'm doing > it right. > > -- https://mail.python.org/mailman/listinfo/python-list
Re: Hi I'm trying to get live data from stock using python , is it possible?
Skip Montanaro writes: > > I want to know if AAPL is more than value 300 and if it does I want it to > > send to me mail with gmail :) . thanks for the help.. > > Try searching pypi.org for "finance", then scroll through the many > returned packages. A few show how to get stock data from Yahoo! or > Google. Yahoo and Google both used to offer APIs for financial data, and matplotlib (later moved into a separate module, mpl_finance) used to have a Python wrapper around Yahoo's API; but Yahoo shut their financial API down in mid-2017 and Google followed suit soon after. See: http://www.financial-hacker.com/bye-yahoo-and-thank-you-for-the-fish/ The comments include links to a lot of possible alternatives. Most of them require API keys and some charge a fee. You should probably try several to find out which works best for you, and expect to update your code every year or two as financial quote services seem to come and go. ...Akkana -- https://mail.python.org/mailman/listinfo/python-list
Re: Cross platform mutex to prevent script running more than instance?
On 04Sep2018 07:57, CFK wrote:
What about using flock()? I don't know if it works on Windows, but it works
really well for Unix/Linux systems. I typically create a log file in a
known location using any atomic method that doesn't replace/overwrite a
file, and flock() it for the duration of the script.
Please adopt the inline reply format. Thanks.
The good things about flock() and open(O_EXCL) and other variations is that if
your program aborts (or its OS aborts) the lock goes away. The downside is that
it is less cross platform (including network filesystems). Even ignoring
nonUNIX systems I have counter examples: I've got a (pretty dumb) embedded
Linux box here whose NFS doesn't support locking. SO flock() goes out the
window if the lock uses it.
Now, many use cases are single machine or may never meaningfully use a network
filesystem. But if I'm writing _library_ code then I, as the author, don't know
who will be calling my code in the future. So my inclination is to go for mkdir
because it is so portable and robust.
The downside with mkdir, and also with pd files really, is that a program or OS
abort can leave them lying around. Being persistent objects, some kind of
cleanup is needed. For me, that is usually a price I'll accept in order to have
a robust works-anywhere tool.
Aside: pid files? How do you know they're really stale? PIDs can be reused. On
Linux and many UNIXes, PIDs get reused really fast (sequentially allocated);
even OpenBSD with its cool unpredictable PIDs has this issue to a lesser
degree.
What you can get away with depends on your use cases. If you like automatic
cleanup, flock and its file descriptor based variants are simple and at least
always go away on program exit, whatever the reason. If you can wear some
cleanup, mkdir is portable and releiable. (And you can store state information
inside the dir!)
Given the subject line ("Cross platform mutex to prevent script running more
than instance") I'd go for mkdir myself.
Cheers,
Cameron Simpson
Thanks,
Cem Karan
On Mon, Sep 3, 2018, 11:39 PM Cameron Simpson wrote:
On 03Sep2018 07:45, Malcolm Greene wrote:
>Use case: Want to prevent 2+ instances of a script from running ...
>ideally in a cross platform manner. I've been researching this topic and
>am surprised how complicated this capability appears to be and how the
>diverse the solution set is. I've seen solutions ranging from using
>directories, named temporary files, named sockets/pipes, etc. Is there
>any consensus on best practice here?
I like os.mkdir of a known directory name. This tends to be atomic and
forbidden when the name already exists, on all UNIX platforms, over remote
filesystems. And, I expect, likewise on Windows.
All the other modes like opening files O_EXCL etc tend to be platform
specific
and not reliable over network filesystems.
And pid based approaches don't work cross machine, if that is an issue.
Cheers,
Cameron Simpson
--
https://mail.python.org/mailman/listinfo/python-list
Re: Verifying the integrity/lineage of a file
Grant Edwards wrote: Writing your own crypto software isn't a problem, and it can be very educational. Just don't _use_ your own crypto software. Okay, so find a friend who also likes writing crypto software, and use each other's software. Problem solved. :-) -- Greg -- https://mail.python.org/mailman/listinfo/python-list
Re: Verifying the integrity/lineage of a file
i think he was referring to a wrapper for a crypto-software Abdur-Rahmaan Janhangeer https://github.com/Abdur-rahmaanJ Mauritius On Sat, 1 Sep 2018, 21:45 Peter Pearson, wrote: > > Writing your own crypto software is fraught with peril, > -- https://mail.python.org/mailman/listinfo/python-list
Re: Pass a list of values as options to 3 dropdown menus
On Tue, 4 Sep 2018 10:13:07 -0700 (PDT), Nick Berg wrote: [snip] > > May i ask how you managed to send an email with a domain > nowhere.invalid ? I would like to do the same. I don't post by sending email, I post by using a news client (slrn), which interacts with the Usenet system (en.wikipedia.org/wiki/News_client), a largely decentralized news-sharing system that dates from the 1970's (I think) and works through the use of a somewhat casual network of servers that circulate messages among themselves. In contrast (if I read your headers right), you read and post by using Google Groups, a newfangled invention that we fossils from the days of gods and giants consider lame and hostile to efficient organization, and we suspect that prolonged use results in an inability to hoist one's trousers above one's buttocks and a tendency to use interrogatory intonation on declarative sentences. -- To email me, substitute nowhere->runbox, invalid->com. -- https://mail.python.org/mailman/listinfo/python-list
Re: Verifying the integrity/lineage of a file
On 2018-09-04 16:13, Grant Edwards wrote: > On 2018-09-01, Peter Pearson wrote: > >> Writing your own crypto software is fraught with peril, and that >> includes using existing libraries. > > Writing your own crypto software isn't a problem, and it can be very > educational. > > Just don't _use_ your own crypto software. > > Howerver, the set of people who write software without intending to > use it is pretty small... > Apart from all the people writing specialist software that's not relevant to their profession (seeing as they're programmers, not whatever the target audience is) intending to sell it. -- https://mail.python.org/mailman/listinfo/python-list
Re: problem with json.dumps / complexjson.loads in python 3.4 virtualenv
"M. Fioretti" writes:
> I have an error in a python application that I installed. I already
> opened an issue about it on the application page at github, but I
> would also greatly appreciate any help to (at least) better debug the
> problem, because I urgently need to use that program.
>
> Details:
>
> I need to run the python client for the shaarli bookmarks manager,
> whose home page is https://github.com/shaarli/python-shaarli-client,
> on a Centos release 7.5 x86_64 server. Since that client requires
> python >= 3.4, and I do not want to move the whole server to that
> version, I created a virtualenv following the instructions at
> https://github.com/shaarli/python-shaarli-client/blob/master/docs/user/installation.rst
>
> When I try to run it, I get the error messages that I already reported
> in full at
>
> https://github.com/shaarli/python-shaarli-client/issues/33
Looks like the problem is immediately at the start of the response
(--> "ValueError: Expecting value: line 1 column 1 (char 0)"),
i.e. the server response is not recognizable as a JSON encoded value.
I would debug your "main" program (I would use the
"pdb" module ("Python DeBugger")) and instead of calling "response.json()"
look at the string value of "response" (likely "json.read()").
This might give you some hint why the server failed to produce
an acceptable response.
> as far as I can understand after some searching, it **may** be the
> problem described at
> https://mcgrattan.org/2017/01/24/ordered-json-in-python-with-requests/
It is very unlikely that this is related.
--
https://mail.python.org/mailman/listinfo/python-list
Re: Error installing libraries
Gilmeh Serda writes: > On Mon, 03 Sep 2018 12:40:49 +0530, ojas gupta wrote: > >> error: Microsoft Visual C++ 14.0 is required. > > Wonder why it doesn't work? At least, the error message is clear: the process needs "Microsoft Visual C++ 14.0". It is installed on your computer? -- https://mail.python.org/mailman/listinfo/python-list
