Re: Getting ASCII encoding where unicode wanted under Py3k
On Mon, 13 May 2013 10:59:33 -0500, Jonathan Hayward wrote: > --e89a8f3b9db145cbab04dc9b9a23 > Content-Type: text/plain; charset=windows-1252 > Content-Transfer-Encoding: quoted-printable > [snipped many lines of quoted-printable muck] > My code is below. What should I be doing differently to be, in the most > immediate sense, calls to '''%(foo)s''' % locals()? [snipped about 200 lines of code, presented in quoted-printable] You will greatly increase your odds of getting a useful response if you post the shortest possible program that exhibits your problem. Posting it as plain text would help, too. -- To email me, substitute nowhere->spamcop, invalid->net. -- http://mail.python.org/mailman/listinfo/python-list
Re: password protect file
On Sat, 29 Jun 2013 10:28:47 -0700 (PDT), gmsid...@gmail.com wrote: > I was wondering if there was a couple of words or things i > could add to the top of my python script to password > protect it so that it asks user for the password and then > after three tries it locks them out or says "access > denied" and closes/ends the script but if they get it > wright it proceeds on to the next line of the script total > noob here any help appreciated You can do this with just a couple lines of Python (and I'm sure this group's experts can show you how better than I), but more importantly, are you aware that doing this doesn't actually make anything secure, unless you also take precautions that are much more complicated than a few lines of Python? If you frankly state that you're only after a kid-sister level of security, readers might feel less conflicted about helping. -- To email me, substitute nowhere->spamcop, invalid->net. -- http://mail.python.org/mailman/listinfo/python-list
Re: howto handle nested for
On Fri, 28 Sep 2012 09:49:36 -0600, Ian Kelly wrote: > > levels = 6 > for combination in itertools.product(xrange(n_syms), levels): > # do stuff >>> n_syms = 3 >>> levels = 6 >>> for combination in itertools.product(xrange(n_syms), levels): ... print combination ... Traceback (most recent call last): File "", line 1, in TypeError: 'int' object is not iterable -- To email me, substitute nowhere->spamcop, invalid->net. -- http://mail.python.org/mailman/listinfo/python-list
Re: SSH Connection with Python
On Thu, 25 Oct 2012 12:16:58 +0200, Schneider wrote: > how can i create a SSH-Connection with python? I have to send some > commands to the remote host and parse their answers. > greatz Johannes I've been using Twisted (twistedmatrix.com). It is especially convenient for the server end. Its organization is "event-driven", which you may or may not find convenient. -- To email me, substitute nowhere->spamcop, invalid->net. -- http://mail.python.org/mailman/listinfo/python-list
Re: SSH Connection with Python - Oops
On 25 Oct 2012 16:55:46 GMT, Peter Pearson wrote: > On Thu, 25 Oct 2012 12:16:58 +0200, Schneider wrote: >> how can i create a SSH-Connection with python? I have to send some >> commands to the remote host and parse their answers. >> greatz Johannes > > I've been using Twisted (twistedmatrix.com). It is especially > convenient for the server end. Its organization is "event-driven", > which you may or may not find convenient. Oops! The question was about SSH, and I was blathering about SSL. Sorry. -- To email me, substitute nowhere->spamcop, invalid->net. -- http://mail.python.org/mailman/listinfo/python-list
Re: String manipulation in python..NEED HELP!!!!
On Tue, 11 Dec 2012 16:39:27 +, duncan smith wrote: [snip] > >>> alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" > >>> key = "XPMGTDHLYONZBWEARKJUFSCIQV" > >>> mapping = {} > >>> for i, ch in enumerate(alpha): > mapping[ch] = key[i] mapping = dict(zip(alpha, key)) -- To email me, substitute nowhere->spamcop, invalid->net. -- http://mail.python.org/mailman/listinfo/python-list
Re: Password hash
On Sun, 23 Dec 2012 20:38:12 -0600, Robert Montgomery wrote: > I am writing a script that will send an email using an account I set up > in gmail. It is an smtp server using tls on port 587, and I would like > to use a password hash in the (python) script for login rather than > plain text. Is this do-able? Details please. No, *you* need to provide details. Security problems nearly always emerge from the details, so it's important to be as clear as possible about what you want to achieve and what the threat is. -- To email me, substitute nowhere->spamcop, invalid->net. -- http://mail.python.org/mailman/listinfo/python-list
Re: Need some help confirming transactions using sha256
On Thu, 31 Jan 2013 08:43:03 -0800 (PST), kryptox.excha...@gmail.com wrote: > I'm wondering if anyone can help me as I can't seem to get > this to work. There is an online dice game that is > provably fair by calculating the 'dice roll' using using a > sha256 hash calculated against my transaction ID generated > by me. The secret used to make the calculation is revealed > at the end of each day thus allowing you to prove they > didn't cheat. So they provide the following to allow you > to verify the calculation of the dice roll: > > Secret used = > r7A7clvs9waizF+6QEiI0tgAq1ar48JItK3kg9kaeAFXz2vsMsHmOd9r9fhkmtxTz3CQnGAPMaDeKLvgb1A2VA > Secret hash > sha256(r7A7clvs9waizF+6QEiI0tgAq1ar48JItK3kg9kaeAFXz2vsMsHmOd9r9fhkmtxTz3CQnGAPMaDeKLvgb1A2VA) > = 48d78d573b9b8e11a13a72d9a78011f2e5d9754d89de47b209f32c51777f535d > Lucky hash > sha256(r7A7clvs9waizF+6QEiI0tgAq1ar48JItK3kg9kaeAFXz2vsMsHmOd9r9fhkmtxTz3CQnGAPMaDeKLvgb1A2VA:108128 > 06653842663997bf5971637f86f26c71a4716276d7fa8f323a83588d91:1) = > dfa8769be81a543002865c88a5b52fa07f3b67fc7cd9b519c3f6a6452bcd48e4 > > Lucky Number 0x48e4 = 18660 > > So, I'm doing the following: > > C:\Python27>python > Python 2.7.3 (default, Apr 10 2012, 23:24:47) [MSC v.1500 64 bit (AMD64)] on > win32 > Type "help", "copyright", "credits" or "license" for more information. import hashlib, hmac txid = 'r7A7clvs9waizF+6QEiI0tgAq1ar48JItK3kg9kaeAFXz2vsMsHmOd9r9fhkmtxTz3CQnGAPMaDeKLvgb1A2VA' secret = '10812806653842663997bf5971637f86f26c71a4716276d7fa8f323a83588d91:1' [snip] >>> txid = >>> 'r7A7clvs9waizF+6QEiI0tgAq1ar48JItK3kg9kaeAFXz2vsMsHmOd9r9fhkmtxTz3CQnGAPMaDeKLvgb1A2VA' >>> secret = >>> '10812806653842663997bf5971637f86f26c71a4716276d7fa8f323a83588d91:1' >>> hashlib.sha256(txid+":"+secret).hexdigest() 'dfa8769be81a543002865c88a5b52fa07f3b67fc7cd9b519c3f6a6452bcd48e4' >>> 0x48e4 18660 >>> . . . which is the number you wanted, right? -- To email me, substitute nowhere->spamcop, invalid->net. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python usage numbers
On 12 Feb 2012 09:12:57 GMT, Steven D'Aprano wrote: > > Suppose you're a fan of Russian punk bank Наӥв and you have a directory > of their music. Sigh. Banking ain't what it used to be. I'm sticking with classical Muzak. -- To email me, substitute nowhere->spamcop, invalid->net. -- http://mail.python.org/mailman/listinfo/python-list
Re: pygame.Rect question
On Sun, 8 Apr 2012 16:58:01 -0700 (PDT), Scott Siegler wrote: [snip] > I set rect.left to 30, rect.top to 30 and rect.width = 20 > > This works fine. However, when looking at rect.right() it > shows that it is equal to 50. I suppose this is equal to > 30+20. However, since the first pixel is on location 30, > wouldn't the 20th pixel be on 49 (not 50)? > > Am I missing something here? It is really confusing me > when I am doing some collision algorithms. I'm not a pygame expert, but . . . it would be consistent with Python's conventions for ranges of indices if rect.right() were the first pixel *outside* the rectangle. Of course, one would expect rect.bottom() to work similarly. If this is the right explanation, it will be useful to picture indices pointing between pixels, rather than at pixels. -- To email me, substitute nowhere->spamcop, invalid->net. -- http://mail.python.org/mailman/listinfo/python-list
Re: syntax for code blocks
On Fri, 27 Apr 2012 13:24:35 +0200, Kiuhnm wrote: > I'd like to change the syntax of my module 'codeblocks' to make it more > pythonic. > > Current Syntax: > > with res << func(arg1) << 'x, y': > print(x, y) > > with res << func(arg1) << block_name << 'x, y': > print(x, y) > > New Syntax: > > with res == func(arg1) .taking_block (x, y): > print(x, y) > > with res == func(arg1) .taking_block (x, y) as block_name: > print(x, y) [snip] Hey, guys, am I the only one here who can't even guess what this code does? When did Python become so obscure? -- To email me, substitute nowhere->spamcop, invalid->net. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python and Tkinter by John E Grayson
On Wed, 16 May 2012 23:55:29 -0400, Mark R Rivet wrote: > I have a copy of this book and was wondering how relevant the content > is considering the publish date is 2000. Are people still using this > information? Anyone have any experience with this book? I bought the book years ago, hoping to learn about Tkinter. I was greatly disappointed: it seems to me that it's a book about Pmw. -- To email me, substitute nowhere->spamcop, invalid->net. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python and Tkinter by John E Grayson
On Thu, 17 May 2012 07:48:50 -0400, Mark R Rivet wrote: > > I am in the process of learning python, and want to learn tkinter for > GUI stuff. Is tkinter what people are using for GUI? Tkinter is one option. PyGUI is another. More suggestions will probably accrete on this thread. -- To email me, substitute nowhere->spamcop, invalid->net. -- http://mail.python.org/mailman/listinfo/python-list
Re: Email Id Verification
On Fri, 25 May 2012 13:36:18 + (UTC), Grant Edwards wrote: [snip] > . . . Nothing will make your users swear at > you as certainly as when you refuse to accept the e-mail address at > which the reeive e-mail all day every day. Amusingly, every time I log into Discovercard's web site, I get a red-letter warning that my registered email address is invalid. Inquiring, I was told that the presence of the substring "spam" anywhere in the address (including "@spamcop.net") makes the address invalid in Discovercard's opinion. -- To email me, substitute nowhere->spamcop, invalid->net. -- http://mail.python.org/mailman/listinfo/python-list
Re: usenet reading
On Sat, 26 May 2012 16:05:23 +0100, duncan smith wrote: > On 25/05/12 23:38, Jon Clements wrote: [snip] >> Is there a server out there where I can get my news groups? > > If you don't mind paying a small fee there are several companies > providing usenet access such as http://www.newsdemon.com. (I didn't have > much joy trying to track down a reliable free service, so now I pay a > few pounds a year.) Also in the pay-a-little category, news.individual.net costs 10 euros per year and filters out spam pretty effectively. I've been happy using it with the slrn news reader for about 4 years. -- To email me, substitute nowhere->spamcop, invalid->net. -- http://mail.python.org/mailman/listinfo/python-list
Re: International translation of docs - is it a scam?
On Tue, 07 Jun 2011 16:55:28 +0200, Alain Ketterlin wrote: > Chris Gonnerman writes: > >> On the 30th of May, I received an email from a man (I'll leave out his >> name, but it was properly male) offering to translate the docs for the >> gdmodule (which I maintain) into Belorussian. [...] > > The same has happened on the gcc list, where it has been considered a > scam. See, e.g., > > http://gcc.gnu.org/ml/gcc/2011-05/msg00046.html > > and messages referenced therein. Interesting. That link leads to a discussion of presumed link farmers using Google Translate to translate other people's pages, in exchange for links. So I asked Google Translate to translate Chris Gonnerman's page, http://newcenturycomputers.net/projects/gdmodule.html , and the results were identical (on cursory examination) to the page produced by Gonnerman's correspondent, as reported in the original post. (I won't post that URL here lest I support the farm.) -- To email me, substitute nowhere->spamcop, invalid->net. -- http://mail.python.org/mailman/listinfo/python-list
Re: Is the mailing list to usenet gateway borked?
On 20 Jun 2011 01:41:44 GMT, Steven D'Aprano wrote: > The last couple of messages on this list show up > fine on the mailman archives, but are empty posts on comp.lang.python. Is > there a problem with the mail -> usenet gateway? I don't see any empty posts on comp.lang.python. Can we talk about a specific post? For example, this recent post is not empty when retrieved from news.individual.net using slrn: To: python-list@python.org From: Terry Reedy Subject: Re: threading : make stop the caller Date: Sun, 19 Jun 2011 12:58:56 -0400 -- To email me, substitute nowhere->spamcop, invalid->net. -- http://mail.python.org/mailman/listinfo/python-list
Re: Is the mailing list to usenet gateway borked?
On 20 Jun 2011 23:49:11 GMT, Steven D'Aprano wrote: [snip] > I will treat this as a bug in Pan, and take it to the appropriate forums, > but for anyone who cares, here's one example: > > From: Steven D'Aprano > Subject: Re: What is this syntax ? > Newsgroups: comp.lang.python > References: <4dfdfc99$0$715$426a3...@news.free.fr> <4dfe10d1$0$28053 > $426a3...@news.free.fr> > dd0c35.16204819062...@news.panix.com> l...@python.org> > MIME-Version: 1.0 > Content-Type: text/plain; charset=UTF-8 > Content-Transfer-Encoding: 8bit > Date: 19 Jun 2011 23:19:56 GMT > Lines: 36 > Message-ID: <4dfe841c$0$30002$c3e8da3$54964...@news.astraweb.com> As you probably expected, that message is displayed normally by slrn. -- To email me, substitute nowhere->spamcop, invalid->net. -- http://mail.python.org/mailman/listinfo/python-list
Re: problem with bcd and a number
On Thu, 04 Aug 2011 21:52:45 +0200, Christoph Hansen wrote: > MRAB schrieb: > >> The value is MSB * 100 + (LSB>> 4) * 10 + (LSB& 0xF) > > i would say > > (MSB >> 4)*100 + (MSB & 0xF)*10 + (LSB >> 4) > > but who knows I concur. I think the documentation is trying to say that the low-order nibble of the LSB is garbage. -- To email me, substitute nowhere->spamcop, invalid->net. -- http://mail.python.org/mailman/listinfo/python-list
Re: lists and for loops
On Wed, 17 Aug 2011 20:08:23 -0700 (PDT), Emily Anne Moravec wrote: > I want to add 5 to each element of a list by using a for loop. > > Why doesn't this work? > > numbers = [1, 2, 3, 4, 5] > for n in numbers: > n = n + 5 > print numbers Because integers are immutable. You cannot turn 1 into 6. Contrast this behavior with lists, which *are* mutable: >>> numbers = [[1],[2],[3],[4],[5]] >>> for n in numbers: ... n[0]= n[0] + 5 ... >>> numbers [[6], [7], [8], [9], [10]] For practical purposes, I'm sure you'll find other responders' excellent posts to be of more immediate use, but keeping mutability in mind helps. -- To email me, substitute nowhere->spamcop, invalid->net. -- http://mail.python.org/mailman/listinfo/python-list
Re: List spam
On Thu, 18 Aug 2011 16:58:04 +0200, Alain Ketterlin wrote: > Ghodmode writes: > > [...] >> Make an effort to curb the spam even if it means killing the newsgroup >> availability. Choose mailman or Google Groups, or another single >> solution. Make it members only, but allow anyone to register with an >> automated confirmation email and a CAPTCHA. Appoint a list admin who >> has a few minutes each day to scan subjects of emails for spammers and >> remove them from the members list. > > Or save work and find a public nntp server (or setup one, or ask your > provider), and use a news reader to follow the list (even thunderbird > can do this). No spam, no need to store messages on your machine, > auto-purge after a configurable delay, etc. Or pay for filtered NNTP service. I'm happy with news.individual.net: 10 euros per year, appears to be competently run, very little spam gets through (maybe like 1 message per heavily posted group per day), and they probably carry all the newsgroups you follow. I have no affiliation with them, except for being a customer who hopes they stay in business. -- To email me, substitute nowhere->spamcop, invalid->net. -- http://mail.python.org/mailman/listinfo/python-list
Re: List spam
On Thu, 18 Aug 2011 12:15:59 -0400, gene heskett wrote: [snip] > What is wrong with the mailing list only approach? In the mailing-list approach, how do I search for prior discussions on a subject? (I'm not particularly opposed to the mailing list, I'm just an NNTP follower worried about the uncertainties of change.) -- To email me, substitute nowhere->spamcop, invalid->net. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python problem
On Mon, 28 Mar 2011 11:38:29 -1000, John Parker wrote: [snip] > I have written the following code so far but get an error. > > infile = open("scores.txt", "r") > lines = infile.readlines() > infile.close() > tokens = lines.split(",") [snip] > error: > Traceback (most recent call last): > File "Score_8.py", line 38, in > tokens = lines.split(",") > AttributeError: 'list' object has no attribute 'split' > > So, what am I doing wrong? infile.readlines returns a list of strings, each string being one line of the input file. Being a list, it doesn't have a "split" attribute. Strings have a "split" attribute. Did you intend to split just one of the input strings? -- http://mail.python.org/mailman/listinfo/python-list
Re: scope of function parameters
On Sun, 29 May 2011 04:30:52 -0400, Henry Olders wrote: [snip] > def main(): > a = ['a list','with','three elements'] > print a > print fnc1(a) > print a > > def fnc1(b): > return fnc2(b) > > def fnc2(c): > c[1] = 'having' > return c > > This is the output: > ['a list', 'with', 'three elements'] > ['a list', 'having', 'three elements'] > ['a list', 'having', 'three elements'] > > I had expected the third print statement to give the same > output as the first, but variable a had been changed by > changing variable c in fnc2. For what it's worth, I've noticed that use of the word "variable" is correlated with a misunderstanding of Python's way of doing things. "Variable" seems to connote a box that has something in it, so when fnc1 passes b to fnc2 which calls it c, you think you have a box named b and a box named c, and you wonder whether the contents of those boxes are the same or different. Python works in terms of objects having names, and one object can have many names. In your example, fnc1 works with an object that it calls b, and which it passes to fnc2, but fnc2 chooses to call that same object c. The names b and c aren't boxes that hold things, they are -- in the words of one of this group's old hands -- sticky-note labels that have been slapped on the same object. -- To email me, substitute nowhere->spamcop, invalid->net. -- http://mail.python.org/mailman/listinfo/python-list
Re: Compression of random binary data
On Tue, 24 Oct 2017 14:51:37 +1100, Steve D'Aprano wrote: On Tue, 24 Oct 2017 01:27 pm, danceswithnumb...@gmail.com wrote: > Yes! Decode reverse is easy..sorry so excited i could shout. Then this should be easy for you: http://marknelson.us/2012/10/09/the-random-compression-challenge-turns-ten/ All you need to do is compress this file: http://marknelson.us/attachments/million-digit-challenge/AMillionRandomDigits.bin to less than 415241 bytes, and you can win $100. Then, on Mon, 23 Oct 2017 21:13:00 -0700 (PDT), danceswithnumbers wrote: > I did that quite a while ago. But 352,954 kb > 415241 bytes, by several orders of magnitude; so you didn't "do that". (Or are we using the European decimal point?) If you're claiming 352,954 *bytes*, not kb, I invite you to explain why you have not collected Mark Nelson's $100 prize, and untold fame and glory; failing which, your credibility will evaporate. -- To email me, substitute nowhere->runbox, invalid->com. -- https://mail.python.org/mailman/listinfo/python-list
Re: Compression of random binary data
On Thu, 26 Oct 2017 19:26:11 -0600, Ian Kelly wrote: > > . . . Shannon entropy is correctly calculated for a data source, > not an individual message . . . Thank you; I was about to make the same observation. When people talk about the entropy of a particular message, you can bet they're headed for confusion. -- To email me, substitute nowhere->runbox, invalid->com. -- https://mail.python.org/mailman/listinfo/python-list
Re: Python Mailing list moderators
On Sun, 5 Nov 2017 17:28:05 -0500, Terry Reedy wrote: > On 11/5/2017 4:14 PM, Cameron Simpson wrote: >> On 05Nov2017 13:09, Στέφανος Σωφρονίου >> wrote: >>> Folks, >>> More and more nonsense are coming in and I find it really difficult to >>> follow any new post that may come and I have to either search for >>> specific content or scroll down until I hit it by accident. >>> >>> Can we do something about it? >>> It's getting really frustrating :/ >> >> It seems from the headers on your message that you're actually using the >> comp.lang.python newsgroup and not the mailing list. The newsgroup is >> completed unmoderated. The mailing list is far less noisy. >> >> Go here: >> >> https://mail.python.org/mailman/listinfo/python-list >> >> and subscribe, and see if things seem better than the newsgroup. > Or point your newsreader to news.gmane.org group > gmane.comp.python.general, which mirrors python-list. [snip] Or use a newsgroup reader that can be easily taught to ignore certain subjects or posters. Or buy your newsgroup service from a provider that does some filtering. I use slrn to read news from news.individual.net, and see only a handful of spam posts on a typical day. -- To email me, substitute nowhere->runbox, invalid->com. -- https://mail.python.org/mailman/listinfo/python-list
Re: Artificial creating of [Lists], is it possible? the best way...
On Thu, 16 Nov 2017 10:47:53 -0800 (PST), jakub.raj...@gmail.com wrote: > Hello, im working on school project, its deck game Sorry! > I need to create specific lists: > My idea is about to using for > For i in range (n): >i=[] This will create n different empty lists, in succession, and discard all but the last one, which will be bound to the name "i". > I know, that there is no possibility to make it from number, but i > havent idea, how to reach my wants Li/L"i"/L(i), how to make possible > for lists? You'll find that the people on this newsgroup are very helpful, but they might (like me) be unable to discern what you're asking. -- To email me, substitute nowhere->runbox, invalid->com. -- https://mail.python.org/mailman/listinfo/python-list
Re: Repeated Names (Repeated Names)
On Sat, 16 Dec 2017 12:56:07 +1300, Gregory Ewing wrote: > Anyone else now getting duplicate posts with the sender's > name repeated in parentheses? Yes. Both of the posts on this thread appear twice, once with and once without the parenthesized name. In each pair, the Date field differed by one second, once in each direction. -- To email me, substitute nowhere->runbox, invalid->com. -- https://mail.python.org/mailman/listinfo/python-list
Re: Python bug report
On Thu, 21 Dec 2017 23:54:17 +0100, Ranya wrote: > Hi, > Am trying to use clr.AddReference and clr.AddReferenceToFile, but > python(2.7) keeps making this error: > > Traceback (most recent call last): > File "", line 1, in > clr.AddReference("UnityEngine")AttributeError: 'module' object has > no attribute 'AddReference' > > How can I fix this? > Thanks in advance. What is clr? Whatever it is, it doesn't have the AddReference attribute that you seem to be expecting. -- To email me, substitute nowhere->runbox, invalid->com. -- https://mail.python.org/mailman/listinfo/python-list
Re: RegExp - please help me!
On Tue, 26 Dec 2017 05:14:55 -0800 (PST), szykc...@gmail.com wrote: [snip] > So: I develop regexp which to my mind should work, but it doesn't and > I don't know why. The broken regexp is like this: > struct (.+)\s*{\s*(.+)\s*}; [snip] You'll probably get better help faster if you can present your problem as a couple lines of code, and ask "Why does this print XXX, when I'm expecting it to print YYY?" (Sorry I'm not smart enough to give you an answer to your actual question.) -- To email me, substitute nowhere->runbox, invalid->com. -- https://mail.python.org/mailman/listinfo/python-list
Re: Compression of random binary data
On Sat, 27 Jan 2018 21:26:06 -0800 (PST), pendrysamm...@gmail.com wrote: > If it is then show him this > > 387,420,489 >= > 00110011 00111000 00110111 00101100 00110100 00110010 0011 0 ... To save the casual reader a moment of disorientation, the above binary string is just the ASCII representation of the text string "387,420,489". > 9^9 = ⬇️ (^ = to the power of) >= 387,420,489 > > But > > 9^9 >= > 00111001 0100 00111001 Similarly, this is the ASCII representation of "9^9". Our self-confessedly intermittently sober correspondent appears to have discovered the backside of the principle that a short text expression can generate a large number. -- To email me, substitute nowhere->runbox, invalid->com. -- https://mail.python.org/mailman/listinfo/python-list
Re: Where has the practice of sending screen shots as source code come from?
On Sun, 28 Jan 2018 20:24:55 -0800, Dan Stromberg wrote: [snip] > > Is it really true that OCR appeared long before Neural Networks > (NN's)? I first heard of NN's in the 80's, but OCR more like the > 90's. In 1964, the IBM exhibit at the World's Fair in New York demonstrated a system that read dates that visitors wrote by hand. (You were supposed to write your date of birth, and the system then printed the New York Times's headline for that date.) -- To email me, substitute nowhere->runbox, invalid->com. -- https://mail.python.org/mailman/listinfo/python-list
Re: checksum problem
On Tue, 30 Jan 2018 11:24:07 +0100, jak wrote: > Hello everybody, > I'm using python 2.7.14 and calculating the checksum with the sha1 > algorithm and this happens: the checksum is wrong until I read the whole > file in one shot. Here is a test program: > > import hashlib > > def Checksum(fname, blocks): > m = hashlib.sha1() > print "sha1 block size: " + str(m.block_size * blocks) > with open(fname, "rb") as fh: > for data in fh.read(m.block_size * blocks): > m.update(data) > return m.hexdigest() > > def main(): > for b in range(10, 260, 10): > print str(b) + ': ' + > Checksum("d:/upload_688df390ea0bd728fdbeb8972ae5f7be.zip", b) > > if __name__ == '__main__': > main() > > and this is the result output: > > sha1 block size: 640 > 10: bf09de3479b2861695fb8b7cb18133729ef00205 > sha1 block size: 1280 > 20: 71a5499e4034fdcf0eb0c5d960c8765a8b1f032d > . > . > . > sha1 block size: 12160 > 190: 956d017b7ed734a7b4bfdb02519662830dab4fbe > sha1 block size: 12800 > 200: 1b2febe05b70f58350cbb87df67024ace43b76e5 > sha1 block size: 13440 > 210: 93832713edb40cf4216bbfec3c659842fbec6ae4 > sha1 block size: 14080 > 220: 93832713edb40cf4216bbfec3c659842fbec6ae4 > . > . > . > > the file size is 13038 bytes and its checksum is > 93832713edb40cf4216bbfec3c659842fbec6ae4 > > Why do I get these results? What am I doing wrong? > > Thanks to everyone in advance. I believe your "for data in fh.read" loop just reads the first block of the file and loops over the bytes in that block (calling m.update once for each byte, probably the least efficient approach imaginable), omitting the remainder of the file. That's why you start getting the right answer when the first block is big enough to encompass the whole file. -- To email me, substitute nowhere->runbox, invalid->com. -- https://mail.python.org/mailman/listinfo/python-list
Re: Where has the practice of sending screen shots as source code come from?
On Mon, 29 Jan 2018 14:46:59 -0500, Dennis Lee Bieber wrote: > On 29 Jan 2018 17:26:32 GMT, Peter Pearson > declaimed the following: > >> >>In 1964, the IBM exhibit at the World's Fair in New York demonstrated >>a system that read dates that visitors wrote by hand. (You were >>supposed to write your date of birth, and the system then printed >>the New York Times's headline for that date.) > > Was it somehow scanning dates from paper or cards, or was it using some > sort of touch sensor input (pressure tablet, or a pen in a harness with > position sensors). > > The first would be OCR proper, while the second is what many PDAs (and > some tablets) rely upon. The second provides actually stroke vector > information on how the characters are formed, which is more reliable than > just seeing pixel transitions and trying to match characters to them. We wrote our dates of birth on paper or punch cards (I forget which) with an ordinary pen. We handed the papers (or cards) to someone who fed them into a machine, which printed slips of paper that were handed to us as we exited. According to the promotional displays, our writing was examined optically; one poster showed a scan path that resembled an extremely prolate cycloid following along the handwritten line. -- To email me, substitute nowhere->runbox, invalid->com. -- https://mail.python.org/mailman/listinfo/python-list
Re: fill out bulletins
On Tue, 14 Jun 2022 00:41:07 +0200, jak wrote: [snip] > > If you are interested in seeing what I called "post office bulletin" > (English is not my language and I don't know the name, sorry), you can > find a sample pdf (fillable) but it works badly here: > > https://www.guardiacostiera.gov.it/venezia/Documents/Bollettino%20MOD.%20TD123.pdf Are these "post office bulletins" always PDFs? -- To email me, substitute nowhere->runbox, invalid->com. -- https://mail.python.org/mailman/listinfo/python-list
mailbox misbehavior with non-ASCII
The following code produces a nonsense result with the input described below: import mailbox box = mailbox.Maildir("/home/peter/Temp/temp",create=False) x = box.values()[0] h = x.get("X-DSPAM-Factors") print(type(h)) # The output is the desired "str" when the message file contains this: To: recipi...@example.com Message-ID: <123> Date: Sun, 24 Jul 2022 15:31:19 + Subject: Blah blah From: f...@from.com X-DSPAM-Factors: a'b xxx ... but if the apostrophe in "a'b" is replaced with a RIGHT SINGLE QUOTATION MARK, the returned h is of type "email.header.Header", and seems to contain inscrutable garbage. I realize that one should not put non-ASCII characters in message headers, but of course I didn't put it there, it just showed up, pretty much beyond my control. And I realize that when software is given input that breaks the rules, one cannot expect optimal results, but I'd think an exception would be the right answer. Is this worth a bug report? -- To email me, substitute nowhere->runbox, invalid->com. -- https://mail.python.org/mailman/listinfo/python-list
Re: Precision Tail-off?
On Tue, 14 Feb 2023 11:17:20 +, Oscar Benjamin wrote: > On Tue, 14 Feb 2023 at 07:12, Stephen Tucker wrote: [snip] >> I have just produced the following log in IDLE (admittedly, in Python >> 2.7.10 and, yes I know that it has been superseded). >> >> It appears to show a precision tail-off as the supplied float gets bigger. [snip] >> >> For your information, the first 20 significant figures of the cube root in >> question are: >>49793385921817447440 >> >> Stephen Tucker. >> -- >> >>> 123.456789 ** (1.0 / 3.0) >> 4.979338592181744 >> >>> 1234567890. ** (1.0 / 3.0) >> 49793385921817.36 > > You need to be aware that 1.0/3.0 is a float that is not exactly equal > to 1/3 ... [snip] > SymPy again: > > In [37]: a, x = symbols('a, x') > > In [38]: print(series(a**x, x, Rational(1, 3), 2)) > a**(1/3) + a**(1/3)*(x - 1/3)*log(a) + O((x - 1/3)**2, (x, 1/3)) > > You can see that the leading relative error term from x being not > quite equal to 1/3 is proportional to the log of the base. You should > expect this difference to grow approximately linearly as you keep > adding more zeros in the base. Marvelous. Thank you. -- To email me, substitute nowhere->runbox, invalid->com. -- https://mail.python.org/mailman/listinfo/python-list
Re: Precision Tail-off?
On Fri, 17 Feb 2023 10:27:08, Stephen Tucker wrote:[Head-posting undone.] > On Thu, Feb 16, 2023 at 6:49 PM Peter Pearson > wrote: >> On Tue, 14 Feb 2023 11:17:20 +, Oscar Benjamin wrote: >> > On Tue, 14 Feb 2023 at 07:12, Stephen Tucker >> wrote: >> [snip] >> >> I have just produced the following log in IDLE (admittedly, in Python >> >> 2.7.10 and, yes I know that it has been superseded). >> >> >> >> It appears to show a precision tail-off as the supplied float gets >> bigger. >> [snip] >> >> >> >> For your information, the first 20 significant figures of the cube root >> in >> >> question are: >> >>49793385921817447440 >> >> >> >> Stephen Tucker. >> >> -- >> >> >>> 123.456789 ** (1.0 / 3.0) >> >> 4.979338592181744 >> >> >>> 1234567890. ** (1.0 / 3.0) >> >> 49793385921817.36 >> > >> > You need to be aware that 1.0/3.0 is a float that is not exactly equal >> > to 1/3 ... >> [snip] >> > SymPy again: >> > >> > In [37]: a, x = symbols('a, x') >> > >> > In [38]: print(series(a**x, x, Rational(1, 3), 2)) >> > a**(1/3) + a**(1/3)*(x - 1/3)*log(a) + O((x - 1/3)**2, (x, 1/3)) >> > >> > You can see that the leading relative error term from x being not >> > quite equal to 1/3 is proportional to the log of the base. You should >> > expect this difference to grow approximately linearly as you keep >> > adding more zeros in the base. >> >> Marvelous. Thank you. [snip] > Now consider appending three zeroes to the right-hand end of N (let's call > it NZZZ) and NZZZ's infinitely-precise cube root (RootNZZZ). > > The *only *difference between RootN and RootNZZZ is that the decimal point > in RootNZZZ is one place further to the right than the decimal point in > RootN. > > None of the digits in RootNZZZ's string should be different from the > corresponding digits in RootN. > > I rest my case. [snip] I believe the pivotal point of Oscar Benjamin's explanation is that within the constraints of limited-precision binary floating-point numbers, the exponent of 1/3 cannot be represented precisely, and is in practice represented by something slightly smaller than 1/3; and accordingly, when you multiply your argument by 1000, its not-quit-cube-root gets multiplied by something slightly smaller than 10, which is why the number of figures matching the "right" answer gets steadily smaller. Put slightly differently, the crux of the problem lies not in the complicated process of exponentiation, but simply in the failure to represent 1/3 exactly. The fact that the exponent is slightly less than 1/3 means that you would observe the steady loss of agreement that you report, even if the exponentiation process were perfect. -- To email me, substitute nowhere->runbox, invalid->com. -- https://mail.python.org/mailman/listinfo/python-list
Re: What do these '=?utf-8?' sequences mean in python?
On Sat, 6 May 2023 14:50:40 +0100, Chris Green wrote: [snip] > So, what do those =?utf-8? and ?= sequences mean? Are they part of > the string or are they wrapped around the string on output as a way to > show that it's utf-8 encoded? Yes, "=?utf-8?" signals "MIME header encoding". I've only blundered about briefly in this area, but I think you need to make sure that all header values you work with have been converted to UTF-8 before proceeding. Here's the code that seemed to work for me: def mime_decode_single(pair): """Decode a single (bytestring, charset) pair. """ b, charset = pair result = b if isinstance(b, str) else b.decode( charset if charset else "utf-8") return result def mime_decode(s): """Decode a MIME-header-encoded character string. """ decoded_pairs = email.header.decode_header(s) return "".join(mime_decode_single(d) for d in decoded_pairs) -- To email me, substitute nowhere->runbox, invalid->com. -- https://mail.python.org/mailman/listinfo/python-list
Re: A beginning beginner's question about input, output and . . .
On Mon, 11 Jan 2021 15:37:58 -0500, DonK wrote: [snip] > > I've seen some Python gui frameworks like Tkinter, PyQt, etc. but they > look kinda like adding a family room onto a 1986 double wide mobile > home, Agreed. Browsergui is not widely popular (I don't think anybody but me has mentioned it on this newsgroup), but it was written to be simple and Pythonic, and has served me well. Browsergui just uses your browser as its user interface. Grab it from https://github.com/speezepearson/browsergui then run "python -m browsergui.examples". (Disclaimer/boast: I'm related to Browsergui's author.) -- To email me, substitute nowhere->runbox, invalid->com. -- https://mail.python.org/mailman/listinfo/python-list
Re: A beginning beginner's question about input, output and . . .
On Wed, 13 Jan 2021 21:46:08 - (UTC), Grant Edwards wrote: > On 2021-01-13, Peter Pearson wrote: [snip] >> Browsergui is not widely popular (I don't think anybody but me has >> mentioned it on this newsgroup), but it was written to be simple and >> Pythonic, and has served me well. Browsergui just uses your browser as >> its user interface. Grab it from >> >> https://github.com/speezepearson/browsergui > > I've been browsing through to documentation and examples, and I don't > see any way to do any sort of modern flexible layout (e.g. nesting > horizontal and vertical flexboxes) where you can control which > elements grow/shrink when the window size changes. > > Is there a way to span columns/rows in a grid or control which columns > grow/shrink? > > Have I missed something? I doubt you've missed anything important, though I'm not sure because I haven't done any of the things you mention. Browsergui is minimalist. If you've done the "python -m browsergui.examples" and don't see something like what you want, it's probably not there. I like Browsergui for simple tools that require a little more interaction than straight command-line utilities: exploring the effect of various value-settings on some curve on a graph, or exploring the ranges of values in a CSV file, or (most recently) rearranging the order of image files in a list. -- To email me, substitute nowhere->runbox, invalid->com. -- https://mail.python.org/mailman/listinfo/python-list
Re: Python cannot count apparently
On Sun, 7 Feb 2021 20:49:52 + (UTC), Kevin M. Wilson wrote: > Set i = 0 at the begin of the code, that way each entry starts at > Logical 0 of the array/container/list... No. The original code, as posted, was >>I recently coded this snippet of code: >>myString=„hello“ >>for i in range(len(myString): >> print(string[i]) Setting i=0 before the "for" statement would make no difference. In the first pass through the for loop, i is set to the first value in the range, which is zero. -- To email me, substitute nowhere->runbox, invalid->com. -- https://mail.python.org/mailman/listinfo/python-list
Re: Not able to use python properly
On Sat, 27 Feb 2021 17:45:42 -0500, Sahaj Verma wrote: > > >I am not able to install and use pip . > >I have installed python 3.9.2 version on my laptop but I am unable to use >pip function. > >Kindly look into this matter as soon as possible. > >Thanking You. > >Sahaj Verma > > > >Sent from [1]Mail for Windows 10 > > > > References > >Visible links >1. https://go.microsoft.com/fwlink/?LinkId=550986 Your chances of getting useful help will be much improved if you provide more information. "I am unable to use pip function" could result from many varied causes. Is your screen completely black? -- To email me, substitute nowhere->runbox, invalid->com. -- https://mail.python.org/mailman/listinfo/python-list
Re: "unexpected argument"
On Tue, 9 Mar 2021 15:03:54 -0500, Quentin Bock wrote: > Error 1: > Space Invaders.py:90: SyntaxWarning: "is" with a literal. Did you mean "=="? > if bullet_state is "fire": > > Error 2: > line 66, in > if event.key == pygame.K_SPACE: > AttributeError: 'Event' object has no attribute 'key' > > Code: > import pygame > import random [snip] > > Why is it saying unexpected argument? > Youtube Tutorial I'm Following: > https://www.youtube.com/watch?v=FfWpgLFMI7w Who is saying "unexpected argument"? I see two error messages, neither of which is "unexpected argument". -- To email me, substitute nowhere->runbox, invalid->com. -- https://mail.python.org/mailman/listinfo/python-list
Re: Uninstall error
On Fri, 12 Mar 2021 17:52:33 +, Premmy wrote: > Hi. I am trying to uninstall python on my computer because i found a better > one but its not getting deleted from control panel. can you please help me Windows? Apple? Linux? -- To email me, substitute nowhere->runbox, invalid->com. -- https://mail.python.org/mailman/listinfo/python-list
Re: Comparing text strings
On Sun, 18 Apr 2021 06:38:16 GMT, Gilmeh Serda wrote: > On Mon, 12 Apr 2021 16:11:21 -0700, Rich Shepard wrote: > >> All suggestions welcome. > > Assuming you want to know which is the oldest version and that the same > scheme is used all the time, could this work? > s1='atftp-0.7.2-x86_64-2_SBo.tgz' s2='atftp-0.7.4-x86_64-1_SBo.tgz' s1>s2 > False s2>s1 > True [snip] However, beware: >>> s2='atftp-0.7.4-x86_64-1_SBo.tgz' >>> s3='atftp-0.7.10-x86_64-1_SBo.tgz' >>> s2>s3 True -- To email me, substitute nowhere->runbox, invalid->com. -- https://mail.python.org/mailman/listinfo/python-list
Re: PYTHON
On Mon, 21 Jun 2021 10:33:26 +0530, Ayaana Soni wrote: > have installed python from your site. After installation my IDLE doesn't > work. IDLE is not in my search list. Plz help!! "Your site" is ambiguous. Does your computer run Windows, Linux, Apple something, ... ? -- To email me, substitute nowhere->runbox, invalid->com. -- https://mail.python.org/mailman/listinfo/python-list
Re: Ask for help on using re
On Thu, 5 Aug 2021 02:40:30 -0700 (PDT), Jach Feng wrote: I want to distinguish between numbers with/without a dot attached: >>> text = 'ch 1. is\nch 23. is\nch 4 is\nch 56 is\n' >>> re.compile(r'ch \d{1,}[.]').findall(text) ['ch 1.', 'ch 23.'] >>> re.compile(r'ch \d{1,}[^.]').findall(text) ['ch 23', 'ch 4 ', 'ch 56 '] I can guess why the 'ch 23' appears in the second list. But how to get rid of it? >>> re.findall(r'ch \d+[^.0-9]', "ch 1. is ch 23. is ch 4 is ch 56 is ") ['ch 4 ', 'ch 56 '] -- To email me, substitute nowhere->runbox, invalid->com. -- https://mail.python.org/mailman/listinfo/python-list
Re: on floating-point numbers
On Thu, 02 Sep 2021 10:51:03 -0300, Hope Rouselle wrote: > import sys sys.version > '3.8.10 (tags/... > ls = [7.23, 8.41, 6.15, 2.31, 7.73, 7.77] sum(ls) > 39.594 > ls = [8.41, 6.15, 2.31, 7.73, 7.77, 7.23] sum(ls) > 39.61 Welcome to the exciting world of roundoff error: Python 3.5.3 (default, Jul 9 2020, 13:00:10) [GCC 6.3.0 20170516] on linux >>> 0.1 + 0.2 + 9.3 == 0.1 + 9.3 + 0.2 False >>> -- To email me, substitute nowhere->runbox, invalid->com. -- https://mail.python.org/mailman/listinfo/python-list
Re: on floating-point numbers
On Thu, 2 Sep 2021 07:54:27 -0700 (PDT), Julio Di Egidio wrote: > On Thursday, 2 September 2021 at 16:51:24 UTC+2, Christian Gollwitzer wrote: >> Am 02.09.21 um 16:49 schrieb Julio Di Egidio: >> > On Thursday, 2 September 2021 at 16:41:38 UTC+2, Peter Pearson wrote: >> >> On Thu, 02 Sep 2021 10:51:03 -0300, Hope Rouselle wrote: >> > >> >>> 39.61 >> >> >> >> Welcome to the exciting world of roundoff error: >> > >> > Welcome to the exiting world of Usenet. >> > >> > *Plonk* >> >> Pretty harsh, isn't it? He gave a concise example of the same inaccuracy >> right afterwards. > > And I thought you were not seeing my posts... > > Given that I have already given a full explanation, you guys, that you > realise it or not, are simply adding noise for the usual pub-level > discussion I must most charitably guess. > > Anyway, just my opinion. (EOD.) Although we are in the world of Usenet, comp.lang.python is by no means typical of Usenet. This is a positive, helpful, welcoming community in which "Plonk", "EOD", and "RTFM" (appearing in another post) are seldom seen, and in which I have never before seen the suggestion that everybody else should be silent so that the silver voice of the chosen one can be heard. -- To email me, substitute nowhere->runbox, invalid->com. -- https://mail.python.org/mailman/listinfo/python-list
Re: nrfutil icorrect installation
On Fri, 8 Oct 2021 14:46:34 -0500, Gerhard van Rensburg wrote: > > I installed Python 3.10.0 > I then install > pip install nrfutil > > When I try to run nrfutil, I get > ModuleNotFoundError: No module named 'constants' I just asked duckduckgo.com about "nrfutil constants", and got this helpful-looking link: https://devzone.nordicsemi.com/f/nordic-q-a/65889/nrfutil-modulenotfounderror-no-module-named-constants -- To email me, substitute nowhere->runbox, invalid->com. -- https://mail.python.org/mailman/listinfo/python-list
Re: installazione numpy
On Mon, 11 Oct 2021 07:56:27 +0200, stefano felli wrote: > l'installazione di numpy con > pip install numpy > fornisce errore > Building wheel for numpy (PEP 517) > > ERROR: Failed building wheel for numpy > Failed to build numpy > ERROR: Could not build wheels for numpy which use PEP 517 and cannot be > installed directly I've seen this problem attributed to a Python / Numpy version-number conflict: https://stackoverflow.com/questions/65708176/troubles-installing-numpy-1-19-5-with-python-3-9-1-on-macos-bigsur -- To email me, substitute nowhere->runbox, invalid->com. -- https://mail.python.org/mailman/listinfo/python-list
Re: Recursion on list
On Thu, 4 Nov 2021 08:57:14 +0100, ast wrote: > > li = [] > > li.append(li) > > li > [[...]] > > >li[0][0][0][0] > [[...]] > > That's funny After the coming AI upheaval, such cruelty to machines will be considered punishable and not funny. -- To email me, substitute nowhere->runbox, invalid->com. -- https://mail.python.org/mailman/listinfo/python-list
Re: A problem with itertools.groupby
On Fri, 17 Dec 2021 09:25:03 +0100, ast wrote: [snip] > > but: > > li = [grp for k, grp in groupby("aahfffddnnb")] > list(li[0]) > > [] > > list(li[1]) > > [] > > It seems empty ... I don't understand why, this is > the first read of an iterator, it should provide its > data. Baffling. Here's a shorter and less readable illustration: >>> list(groupby("aabbb")) [('a', ), ('b', )] >>> list(groupby("aabbb"))[0] ('a', ) >>> list(list(groupby("aabbb"))[0][1]) [] -- To email me, substitute nowhere->runbox, invalid->com. -- https://mail.python.org/mailman/listinfo/python-list
Re: strange problem building non-pure wheel for apple M1 arm64
On Mon, 7 Mar 2022 16:22:10 +, Robin Becker wrote: [snip] > > gcc -bundle -undefined dynamic_lookup -g -arch arm64 [snip] > -L/usr/local/lib > -L/usr/lib > -L/Library/Frameworks/Python.framework/Versions/3.9/lib > -lfreetype [snip] > > ld: warning: ignoring file /usr/local/lib/libfreetype.dylib, building > for macOS-arm64 but attempting to link with file > built for macOS-x86_64 > > The above message seems bizarre; everything is compiled for arm64, but > gcc doesn't want to use an arm64 dylib. > > Can macos experts assist? I am not at all expert in MacOS or any of the specifics of this problem, but I think you want to try to prove that the libfreetype invoked by "-lfreetype" is built for macOS-arm64 rather than for macOS-x86-64. -- To email me, substitute nowhere->runbox, invalid->com. -- https://mail.python.org/mailman/listinfo/python-list
Re: What to do to correct the error written below:
On Sat, 9 Apr 2022 04:59:05 -0700 (PDT), NArshad wrote: > I have accidentally deleted one account in a Django project because of > which one of the pages is no more accessible and is giving the error > written below: > > IndexError at /view_issued_book/ > list index out of range > > and the error is in the line: > > t=(students[i].user,students[i].user_id,books[i].name,books[i].isbn,issuedBooks[0].issued_date,issuedBooks[0].expiry_date,fine) > [snip] Without seeing more of the code, one can only guess, but it appears that the data being processed reside in arrays named "students" and "books", which are indexed by an integer i. The "list index out of range" error probably results from i being too large -- running off the end of the array, perhaps because of the deleted account. You could confirm this by printing i, len(students), and len(books) just before the failing line. -- To email me, substitute nowhere->runbox, invalid->com. -- https://mail.python.org/mailman/listinfo/python-list
Re: What to do to correct the error written below:
On Mon, 11 Apr 2022 00:14:49 -0700 (PDT), NArshad wrote: [snip] > books = list(models.Book.objects.filter(isbn=i.isbn)) > students = list(models.Student.objects.filter(user=i.student_id)) > i=0 > for l in books: > > t=(students[i].user,students[i].user_id,books[i].name,books[i].isbn,issuedBooks[0].issued_date,issuedBooks[0].expiry_date,fine) > i=i+1 > details.append(t) [snip] Is this homework? In this newsgroup, by custom, homework problems should be announced as such, since the best answer to a homework question is different from the best answer to a real-life problem. Back to the problem: By looping over elements in "books" and incrementing counter i, which is used as an index both for "books" and for "students", you will produce an error whenever the number of books exceeds the number of students. Is there some reason to assume that the number of books cannot exceed the number of students? -- To email me, substitute nowhere->runbox, invalid->com. -- https://mail.python.org/mailman/listinfo/python-list
Re: What to do to correct the error written below:
On Tue, 12 Apr 2022 04:56:22 -0700 (PDT), NArshad wrote: > >>By looping over elements in "books" and incrementing counter i, >>which is used as an index both for "books" and for "students", >>you will produce an error whenever the number of books exceeds >>the number of students. Is there some reason to assume that the >>number of books cannot exceed the number of students? > > Since this is an online library the number of students can be any when > compared to number of books or the number of students has nothing to > do with the number of books. 1. The code assumes that the number of books does not exceed the number of students. 2. You report that the number of students has nothing to do with the number of books. 3. Therefore we have identified an erroneous assumption in the code. Mystery solved. -- To email me, substitute nowhere->runbox, invalid->com. -- https://mail.python.org/mailman/listinfo/python-list
Re: How to split value where is comma ?
On Wed, 7 Sep 2016 08:51:36 -0700 (PDT), Asad ur Rehman wrote: [snip] > sofia/external/1203632525,CS_EXECUTE, > Outbound Call, > 12036325259, > ,12036325259, > , > ,ACTIVE, > 9047125683, > 9047125683, > RECV, > 75a9d3ee-7511-11e6-a115-89a1f4981d2c, > vb-pmedia,7841c6c0-7511-11e6-a139-89a1f4981d2c, > outbound,2016-09-07 11:40:57,1473262857,sofia/external/16189973135, > > where is a comma there should start new line ... How can i do it ? Is your question "Given a string that may contain some commas, how do I insert a newline after each comma"? (Note that that is *not* what you show, but from what you show I can't tell what you want.) -- To email me, substitute nowhere->runbox, invalid->com. -- https://mail.python.org/mailman/listinfo/python-list
Re: Can this be easily done in Python?
On Tue, 27 Sep 2016 12:58:40 -0700 (PDT), TUA wrote: > Is the following possible in Python? > > Given how the line below works > > TransactionTerms = 'TransactionTerms' > > > have something like > > TransactionTerms = > > that sets the variable TransactionTerms to its own name as string > representation without having to specify it explicitly as in the line > above You say "variable", but the use of that word often signals a misunderstanding about Python. Python has "objects". An object often has a name, and in fact often has several names. Attempting to associate an object with "its name" looks like a Quixotic quest to me. -- To email me, substitute nowhere->runbox, invalid->com. -- https://mail.python.org/mailman/listinfo/python-list
Re: How to call this method from main method
On Tue, 27 Sep 2016 23:44:11 -0700 (PDT), prasanthk...@gmail.com wrote: [snip] > > if __name__ == '__main__': > > GenAccessToken("This_is_a_Test_QED_MAC_Key_Which_Needs_to_be_at_Least_32_Bytes_Long", > "default", "default", 6, >"g,m,a,s,c,p,d") > > When i am calling the above method from main method it is not > returning the value but when i use print it is showing the value. Is > there any wrong in returning the value from a method. How do you know it's not returning a value? You don't save the return value anywhere. -- To email me, substitute nowhere->runbox, invalid->com. -- https://mail.python.org/mailman/listinfo/python-list
Re: Counting words in a string??
On Fri, 30 Sep 2016 11:37:19 -0700 (PDT), Jake wrote: > Hi, I need a program which: > 1) Asks the user for a sentence of their choice (not including punctuation) > 2) Ask the user which word they would like to know is repeated > 3) Print out to the user how many times the word came up which they chose >from their sentence. > > It would help if you could comment the code. > Thankyou in advance!! Welcome to the Python newsgroup. Many helpful, capable, and polite people frequent this newsgroup, but doing someone's homework assignment is not viewed as helpful. If you write the code and run into a problem, then you can post the code here (if it's short) with a specific question, and will probably get a prompt and very helpful response. -- To email me, substitute nowhere->runbox, invalid->com. -- https://mail.python.org/mailman/listinfo/python-list
Re: Need help for the print() function with a better order
On Sat, 1 Oct 2016 18:12:29 -0700 (PDT), 38016226...@gmail.com wrote: > I am trying to print a simple decision tree for my homework. > The answer must keep in this format: > > Top 7,4,0.95 > career gain = 100 > 1.Management 2, 3, 0.9709505944546686 > 2.Service 5, 1, 0.6500224216483541 > location gain = 100 > 1.Oregon 4, 1, 0.7219280948873623 > 2.California 3, 3, 1.0 > edu_level gain = 100 > 1.High School 5, 1, 0.6500224216483541 > 2.College 2, 3, 0.9709505944546686 > years_exp gain = 100 > 1.Less than 3 3, 1, 0.8112781244591328 > 2.3 to 10 2, 1, 0.9182958340544896 > 3.More than 10 2, 2, 1.0 > > Here is my code: > features={'edu_level':['High School', 'College'], 'career':['Management', 'Service'], 'years_exp':['Less than 3', '3 to 10', 'More than 10'], 'location':['Oregon', 'California']} > > print('Top 7,4,0.95') > for key in features: > print('{} gain = {}'.format(key,100)) > attributes_list=features[key] > kargs={} > for i in range(len(attributes_list)): > kargs[key]=attributes_list[i] > low=table.count('Low',**kargs) > high=table.count('High',**kargs) > print('\t{}.{} {}, {}, {}'.format( i+1,attributes_list[i],low,high,entropy(low,high))) > > I set all the gain as 100 now.But actually the gain must calculate > with the data below. For example, the career gain need the data of > 'Management' and 'Service'. I don't know how to do. or Anyone can > provide me a better logic? I interpret your question as meaning that the value that you print after "gain =" should depend on features[key]. To do that, you'll need to insert a line resembling gain = gain_from_features(features[key]) before the print statement. You'll have to write the gain_from_features function, and provide it with the numbers from which it will compute the gain. As a stylistic suggestion, note that Python allows you to break your "features=" line into a more readable format, as I have done above. Another stylistic suggestions: for key, attributes_list in features.iteritems(): -- To email me, substitute nowhere->runbox, invalid->com. -- https://mail.python.org/mailman/listinfo/python-list
Re: python (scipy) TypeError
On Mon, 3 Oct 2016 09:14:23 -0700 (PDT), chrischris201...@gmail.com wrote: [snip] > > i try to follow some tutorial but i have that error : > > Traceback (most recent call last): > File "C:\Python27\test\test\earth.py", line 42, in > slope_array = np.ones_like(data_array) * nodataval > TypeError: unsupported operand type(s) for *: 'int' and 'NoneType' > > > first i define that lines of code : > > data_array = raster2array(filename) > nodataval = getNoDataValue(filename) > > and the line with error : > > slope_array = np.ones_like(data_array) * nodataval > > how can i fix this error ?i change type field ? > > on the four prints: > > print(resolution) > print(nodataval) > print(type(data_array)) > print(data_array.shape) > > i take that exports : > > {'east-west': 0.0002778, 'north-south': 0.0002778} > None > > (3601, 3601) The TypeError error message is telling you that in the line slope_array = np.ones_like(data_array) * nodataval you're attempting to multiply something of type "int" by something of type "NoneType". And look, when you printed nodataval, you got "None". So, the real question is why getNoDataValue is returning None. To answer that question, I would have to know something about the osgeo package and your input file dem.tif, but unfortunately I don't. -- To email me, substitute nowhere->runbox, invalid->com. -- https://mail.python.org/mailman/listinfo/python-list
Re: Overlapping co-ordiantes of rectangles fail to print in python
On Thu, 17 Nov 2016 06:27:49 -0800 (PST), aruns...@gmail.com wrote: > I am working with following code in which I am trying to output co > ordinates of overlapping rectangles.. However the code fails to > output the co ordinates. I am customizing the following code [about 100 lines of code removed] > Where I need to change the code to output all overlapping rectangles > and its co ordinates? First, insert a print statement to determine whether the problem is (a) no overlapping rectangles are being found, or (b) the overlapping rectangles that are found are not being printed. If (a), proceed to investigate whether (a1) there are, in fact, no overlapping rectangles, or (a2) your code is failing to recognize overlapping rectangles. And so forth . . . -- To email me, substitute nowhere->runbox, invalid->com. -- https://mail.python.org/mailman/listinfo/python-list
Re: OT - "Soft" ESC key on the new MacBook Pro
On Tue, 13 Dec 2016 19:06:45 -0600, Skip Montanaro wrote: > I know this isn't a Python-specific question, but [snip] > Yes, I know I can use C-[ or the Alt key instead of ESC. I know this isn't the sort of answer you wanted, but . . . Train your fingers to use C-[. I did, decades ago, because the darn escape key kept changing places from one keyboard to the next. Combined with the ease with which one can remap the CTRL key to a familiar place, C-[ has been a blessing. -- To email me, substitute nowhere->runbox, invalid->com. -- https://mail.python.org/mailman/listinfo/python-list
Re: OT - "Soft" ESC key on the new MacBook Pro
On Wed, 14 Dec 2016 11:50:30 -0600, Skip Montanaro wrote: > On Wed, Dec 14, 2016 at 11:40 AM, Peter Pearson > wrote: >> Train your fingers to use C-[. > > As I recall, the location of the Ctrl key was one of the differences > between Sun and PC101 keyboards. Doesn't matter so much now, as Sun > has gone the way of the dodo, but it moved around more for me than ESC > over the years. Absolutely right. Random migrations of the Ctrl key annoyed so many of us set-in-our-ways geezers that Linux distributions always seem to come with an easily activated option to put the Ctrl key where it belongs, namely to the left of the A, right where God put it on Adam's ASR 33. -- To email me, substitute nowhere->runbox, invalid->com. -- https://mail.python.org/mailman/listinfo/python-list
Re: [OT] Security question
On Thu, 22 Dec 2016 12:10:40 +0200, Frank Millman wrote: [snip] > > What about the second part of my query? Is it acceptable that they keep > passwords on their system in clear text? Absolutely not. Keeping the passwords, even encrypted, is a reckless invitation to disaster. Chris has done a fine job of explaining the situation; I'm just piling on (as a retired cryptologist) to add statistical weight to your survey. -- To email me, substitute nowhere->runbox, invalid->com. -- https://mail.python.org/mailman/listinfo/python-list
Re: I need a lot of help...
On Sat, 24 Dec 2016 02:27:05 -0800 (PST), raulmaqueda6...@gmail.com wrote: > I do not know how to do this exercise, does anyone help me? > > Define the matrix_range (m) function that returns the range of an > array calculated by the Gaussian method. > > It should work with any number of rows and columns. No punctuation > will be given to deliveries that do not respect this requirement. > > Operating example: > matrix_range ([[1,0,0], [0,1,0], [0,0,1]]) > 3 I don't know any definition of "matrix range" that fits this description. Is it possible that someone means "rank"? -- To email me, substitute nowhere->runbox, invalid->com. -- https://mail.python.org/mailman/listinfo/python-list
Sockets: IPPROTO_IP not supported
Trying to sniff Ethernet packets, I do this: s = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_IP) but it results in this: $ sudo python3 sniff_survey.py Traceback (most recent call last): File "sniff_survey.py", line 118, in s = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_IP) File "/usr/lib/python3.2/socket.py", line 94, in __init__ _socket.socket.__init__(self, family, type, proto, fileno) socket.error: [Errno 93] Protocol not supported Anybody know what I'm doing wrong? (Python 3.2.3 under Debian 3.2.84-1.) -- To email me, substitute nowhere->runbox, invalid->com. -- https://mail.python.org/mailman/listinfo/python-list
Re: Sockets: IPPROTO_IP not supported
On Mon, 16 Jan 2017 10:17:06 +, Joseph L. Casale wrote: >> Trying to sniff Ethernet packets, I do this: >> >>s = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_IP) >> >> but it results in this: >> >> $ sudo python3 sniff_survey.py >> Traceback (most recent call last): >> File "sniff_survey.py", line 118, in >> s = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_IP) >> File "/usr/lib/python3.2/socket.py", line 94, in __init__ >> _socket.socket.__init__(self, family, type, proto, fileno) >> socket.error: [Errno 93] Protocol not supported >> >> Anybody know what I'm doing wrong? (Python 3.2.3 under Debian 3.2.84-1.) > > Have a look at the bottom of this SO question: > http://stackoverflow.com/questions/5385312/ipproto-ip-vs-ipproto-tcp-ipproto-udp That discussion was helpful. Thanks. Still, I'm not out of the woods. From bmargulies's answer at that link, "IPPROTO_IP is for raw IP packets", which sounds like what I want. But when I use AF_INET, SOCK_RAW, and IPPROTO_IP, I get the "Protocol not supported" error as shown above. >From the link you provided and "man socket", I was inspired to flail about, finding this: domaintypeprotocol result --- -- - AF_INET SOCK_RAWIPPROTO_IP "Protocol not supported" AF_INET SOCK_RAWIPPROTO_IPIP Sees nothing AF_INET SOCK_RAWIPPROTO_TCP Sees TCP traffic, no "dig", no "ping" AF_INET SOCK_RAWIPPROTO_UDP Sees DNS ("dig", but not "ping") AF_INET SOCK_RAWIPPROTO_ICMP Sees "ping", but not "dig" AF_INET SOCK_RAWIPPROTO_RAW Sees nothing AF_INET SOCK_RAW0 "Protocol not supported" AF_INET SOCK_STREAM 0 "Transport endpoint is not connected" AF_INET SOCK_DGRAM 0 Sees nothing AF_INET SOCK_RDM0 "Socket type not supported" AF_IPXSOCK_RAWIPPROTO_RAW "Socket type not supported" AF_PACKET SOCK_RAWIPPROTO_RAW Sees nothing AF_PACKET SOCK_RAWIPPROTO_TCP Sees nothing So I can receive TCP traffic through one socket, and UDP traffic through another socket, and ICMP traffic through a third; but I would like to see all IP packets, regardless of higher-level protocol, and would prefer to get them through a single pipe. (Perhaps it's unreasonable for me to ask something as high-level as a socket to give me something as low-level as a raw packet.) My starting point, by the way, was sample code for "a very simple network sniffer", presented at docs.python.org/3/library/socket.html, which opened the socket with s = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_IP) which is the line that results in the "Protocol not supported" error on my system. (That sample code is labelled as being "for Windows", so the document is not in error.) -- To email me, substitute nowhere->runbox, invalid->com. -- https://mail.python.org/mailman/listinfo/python-list
Re: String Replacement
On Mon, 23 Jan 2017 13:23:38 -0800 (PST), subhabangal...@gmail.com wrote: > I have a string like > > "Trump is $ the president of USA % Obama was $ the president > of USA % Putin is $ the premier of Russia%" > > Here, I want to extract the portions from $...%, which would be > > "the president of USA", > "the president of USA", > "the premier of Russia" [snip] This might get you started: $ cat temp.py import re x = ("Trump is $ the president of USA % Obama was $ the pres" "ident of USA % Putin is $ the premier of Russia%") for y in re.finditer(r"(?P[^\$]*)\$(?P[^%]*)%", x): print("'{0}' -- '{1}'".format(y.group("first"), y.group("second"))) $ python3 temp.py 'Trump is ' -- ' the president of USA ' ' Obama was ' -- ' the president of USA ' ' Putin is ' -- ' the premier of Russia' -- To email me, substitute nowhere->runbox, invalid->com. -- https://mail.python.org/mailman/listinfo/python-list
Re: count points where is within the polygons using shapely and fiona
On Sun, 29 Jan 2017 11:42:47 -0800 (PST), Xristos Xristoou wrote: > i tried to count points from the point shapefile where is within in > the polygon shapefile but i fail.Maybe my code is complete wrong but i > tried. > any idea how to fix my code ? > i want fast method because i have big data features > from shapely.geometry import shape > import fiona > > filepath1 = "point.shp" > file1features = [] > intersectfeatures_file1 = [] > intersectfeatures_file2 = [] > count =0 > count=count+1 This is an illogical place to increment count. > outschema = None > with fiona.collection(filepath1, "r") as input1: > outschema = input1.schema.copy() > for p1 in input1: > file1features.append(p1) I believe you could also say file1features = list(input1). > filepath2 = "polygon.shp" > with fiona.collection(filepath2, "r") as input2: > for p2 in input2: > for p1 in file1features: > [count for i in > [shape(p1['geometry']).within(shape(p2['geometry']))]] The above line produces a list that is discarded because it is not assigned any name. > if p1 not in intersectfeatures_file1: > intersectfeatures_file1.append(p1) > if p2 not in intersectfeatures_file2: > intersectfeatures_file2.append(p2) > > print count > ''' > if intersectfeatures_file1: > outfile = "outputfile1.shp" > with fiona.collection(outfile, "w", "ESRI Shapefile", outschema) as > output: > for outfeature in intersectfeatures: > output.write(outfeature) > if intersectfeatures_file2: > outfile = "outputfile2.shp" > with fiona.collection(outfile, "w", "ESRI Shapefile", outschema) as > output: > for outfeature in intersectfeatures: > output.write(outfeature) > ''' The above lines between triple quotes should have been omitted from this post. > on the print count i take 20 times the number 1. after for this count i want > to export to new shapefile the polygons where have specific number of points. > thnx -- To email me, substitute nowhere->runbox, invalid->com. -- https://mail.python.org/mailman/listinfo/python-list
Re: Python3 using requests to grab HTTP Auth Data
On Wed, 1 Feb 2017 07:10:39 -0800 (PST), Νίκος Βέργος wrote: > # Give user the file requested > url = "http://superhost.gr/data/files/%s"; % realfile > > user, password = 'user', 'passwd' > > r = requests.get( url, auth = (user, password) ) # send auth unconditionally > r.raise_for_status() >== > > How can i ASK the user for http auth data and store them isntead of > giving them to the script? Maybe like this? user = raw_input("User: ") password = raw_input("Password: ") -- To email me, substitute nowhere->runbox, invalid->com. -- https://mail.python.org/mailman/listinfo/python-list
Re: seeking deeper (language theory) reason behind Python design choice
On Wed, 09 May 2018 12:51:15 -0700, Paul Rubin wrote: > Dennis Lee Bieber writes: >> Yes, code reviews may catch such errors... and later, when the >> summary of errors is analyzed for suggestions on how to reduce them -- >> the odds are good that "assignment expressions" will be banned in the >> style documents for that language at the company. > > I don't think I've worked on any C programs with that style restriction > and I can't think of any times when I found that type of bug in deployed > code. I've made the error once or twice while coding, but caught it > right away during inspection or testing. Banning it seems > counterproductive. I could imagine having it flagged by a compiler > warning that can be locally disabled by a pragma. Interestingly, the problem is broader than inadvertently making the mistake yourself; it includes catching deliberate misdirection by others. In the famous "Linux Backdoor Attempt of 2003" (https://freedom-to-tinker.com/2013/10/09/the-linux-backdoor-attempt-of-2003/), somebody who I think never got caught introduced these lines into the code for the wait4 function: if ((options == (__WCLONE|__WALL)) && (current->uid = 0)) retval = -EINVAL; Setting the user ID to zero confers root privileges. - Peter -- https://mail.python.org/mailman/listinfo/python-list
Re: Indented multi-line strings
On Fri, 1 Jun 2018 15:57:58 +0100, Paul Moore wrote: > On 1 June 2018 at 15:36, Dan Strohl via Python-list > wrote: >> So... how does one go about suggesting changes to the built in types? [snip] > > Why does this need to be a string method? Why can't it be a standalone > function? Yes, please, let's content ourselves with a standalone function. Adding features to a language imposes costs in several ways, including hindering newcomers and making code version-dependent. To full-time Python developers, these costs appear small, because they are amortized over a lot of Python activity; but they are encumbrances to the spread and casual use of the language. It seems as if the destiny of every language is to be adorned by its enthusiasts with so many arcane and specialized optimizations -- every one an obvious improvement -- that the world's interest drifts to something newer and cleaner. -- https://mail.python.org/mailman/listinfo/python-list
Re: Attachments (was: How can an int be '+' with a tuple?)
On Sun, 3 Jun 2018 20:20:32 +0200, Peter J. Holzer wrote: [snip] > On 2018-06-03 13:57:26 +1000, Ben Finney wrote: >> (For good reasons, attachments are dropped when messages are distributed >> on the forum.) > > By "the forum" you mean Gmane? (I got the attachment over the mailing > list) Comp.lang.python is a usenet newsgroup, also accessible through a mailing list (and, I think, a web interface). NNTP, the Network News Transfer Protocol, does not provide for attachments. -- https://mail.python.org/mailman/listinfo/python-list
Re: Stefan's headers [was:Names and identifiers]
On Thu, 7 Jun 2018 01:23:31 + (UTC), Steven D'Aprano wrote: > Disclaimer: Ido not see Stefan's original post. I recall that he has set > some sort of header on his posts which means they are not processed by > Gmane, but unfortunately I no longer have any of his posts in my cache > where I can check. > > If anyone else is getting Stefan's posts, can you inspect the full > headers and see if there is a relevant header? Here's the full header, as received by slrn from news.individual.net: Path: uni-berlin.de!not-for-mail From: r...@zedat.fu-berlin.de (Stefan Ram) Newsgroups: comp.lang.python Subject: Names and identifiers Date: 6 Jun 2018 18:37:46 GMT Organization: Stefan Ram Lines: 26 Expires: 1 Aug 2018 11:59:58 GMT Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Trace: news.uni-berlin.de y/fWNNOsUiR8l3NiIdt8QQKv4EmIpqY+4EFRjM4L9WcmK0 X-Copyright: (C) Copyright 2018 Stefan Ram. All rights reserved. Distribution through any means other than regular usenet channels is forbidden. It is forbidden to publish this article in the Web, to change URIs of this article into links,and to transfer the body without this notice, but quotationsof parts in other Usenet posts are allowed. X-No-Archive: Yes Archive: no X-No-Archive-Readme: "X-No-Archive" is only set, because this prevents some services to mirror the article via the web (HTTP). But Stefan Ram hereby allows to keep this article within a Usenet archive serverwith only NNTP access without any time limitation. X-No-Html: yes Content-Language: en Xref: uni-berlin.de comp.lang.python:794657 -- https://mail.python.org/mailman/listinfo/python-list
Re: Sorting NaNs
On Thu, 07 Jun 2018 19:02:42 +1200, Gregory Ewing wrote: > Steven D'Aprano wrote: >> But if it were (let's say) 1 ULP greater or less >> than one half, would we even know? > > In practice it's probably somewhat bigger than 1 ULP. > A typical PRNG will first generate a 32-bit integer and > then map it to a float, giving a resolution coarser than > the 52 bits of an IEEE double. > > But even then, the probability of getting exactly 0.5 > is only 1/2^32, which you're not likely to notice. But gosh, if there are only 2**32 different "random" floats, then you'd have about a 50% chance of finding a collision among any set of 2**16 samples. Is that really tolerable? -- https://mail.python.org/mailman/listinfo/python-list
Re: Sorting NaNs
On Fri, 8 Jun 2018 02:15:02 + (UTC), Steven D'Aprano wrote: > On Thu, 07 Jun 2018 20:43:10 +0000, Peter Pearson wrote: [snip] >> >> But gosh, if there are only 2**32 different "random" floats, then you'd >> have about a 50% chance of finding a collision among any set of 2**16 >> samples. Is that really tolerable? > > Why wouldn't it be? It would be shocking if a sufficiently large sequence > of numbers contained no collisions at all: that would imply the values > were very much NON random. [snip] > . . . I understand that Python's Mersenne Twister implementation > is based on 64-bit ints. OK, I'll relax, particularly since Michael Lamparski's experiment strongly indicates that random floats are drawn from a population much larger than 2**16. You're completely correct, of course, in noting that an absence of collisions would condemn the random-number generator just as badly as an excess. What bothered me was my feeling that a "reasonable observer" would expect the random-float population to be much larger than 2**32, and the probably-collision-free sample size to be accordingly much larger than 2**16, which is, after all, small enough to appear in many applications. Exactly what the "reasonable observer" would expect that population to be, I don't know. To a mathematician, there's zero chance of collision in any finite sample of real numbers, or even just rational numbers; but I don't think anybody would expect that from a computer. When I picture the diligent software engineer asking himself, "Wait, how large can I make this sample before I'll start seeing collisions," I imagine his first guess is going to be the size of a float's mantissa. What applications would have to worry about colliding floats? I don't know. I'm coming from cryptology, where worrying about such things becomes a reflex. -- To email me, substitute nowhere->runbox, invalid->com. -- https://mail.python.org/mailman/listinfo/python-list
Re: What data types does matplotlib pyplot take?
On Wed, 13 Jun 2018 12:53:57 -0400, C W wrote: > Hi everyone, > > I'm curious what data types pyplot takes. It seems that it can take numpy > series, pandas series, and possibly pandas dataframe? How many people data > types are out there? Is that true for all functions in like hist(), bar(), > line(), etc? I regret that this might seem less than helpful, but someone should point out that an enumeration beginning "This package works with the following data types" would be antithetical to Python's "duck-typing" philosophy. The important thing is not an object's type, but whether the object has the attributes and methods required. -- To email me, substitute nowhere->runbox, invalid->com. -- https://mail.python.org/mailman/listinfo/python-list
Re: Understanding memory location of Python variables
On Sat, 16 Jun 2018 09:38:07 -0700 (PDT), ip.b...@gmail.com wrote: > Hi everyone, > > I'm intrigued by the output of the following code, which was totally > contrary to my expectations. Can someone tell me what is happening? > myName = "Kevin" id(myName) > 47406848 id(myName[0]) > 36308576 id(myName[1]) > 2476000 You left out one of the more interesting (and possibly informative) angles: >>> myName = "Kevin" >>> x0 = myName[0] >>> x1 = myName[1] >>> x01 = myName[0:2] >>> y0 = "K" >>> y1 = "e" >>> y01 = "Ke" >>> id(x0) == id(y0) True >>> id(x1) == id(y1) True >>> id(x01) == id(y01) False >>> x01 == y01 True myName[0] is the string "K", and this Python implementation happens to economize by having only a single object "K". This economy measure probably only applies to single-character strings. -- To email me, substitute nowhere->runbox, invalid->com. -- https://mail.python.org/mailman/listinfo/python-list
Re: write the values of an ordered dictionary into a file
On Thu, 21 Jun 2018 22:41:48 +0530, Ganesh Pal wrote: [snip] [what I think OP wants:] > > *.* > > *||STUDENT NAME||STUDENT AGE||MARKS SCORED||PASSED YEAR||FEES PAID||* > > *||John|| 28 || 13|| 2018 || 250 ||* > > > Questions: > > (1) Below is my partial solution , any comments and suggestions ( I am not > to get the “||” delimiter correctly, trying it ) > > #!/usr/bin/python > # A Python program to write the values of an OderedDict into a file > # The values should be formatted correctly under its headers > > from collections import OrderedDict > > tmp = '/tmp/student_record.txt' > student = [("NAME", "John"), >("AGE", 28), >("SCORE", 13), >("YEAR", 2018), >("FEE", 250)] > > student = OrderedDict(student) > header_list = ["STUDENT NAME", "STUDENT AGE", "MARKS SCORED", "PASSED YEAR", > "FEES PAID"] > > header_string = '||' + '||'.join(header_list) + '||' > with open(tmp, 'a') as fd: > for item in header_string: > fd.write("%s" % (item)) > > for value in student.values(): > fd.write("\n") > fd.write("||") > fd.write("%s" % (value)) > > *output:* > *root@X1:/Play_ground/SPECIAL_TYPES# cat /tmp/student_record.txt* > *||STUDENT NAME||STUDENT AGE||MARKS SCORED||PASSED YEAR||FEES PAID||* > *||John* > *||28* > *||13* > *||2018* [snip] You don't say which aspects of this output you find unsatisfactory and want help with, but . . . - You're writing "\n" in front of every *field*, when you only want to write it in front of every line; and - To make the columns line up right, you'll want to specify the widths of the character strings being written, e.g., using "%10s" in place of "%s". -- To email me, substitute nowhere->runbox, invalid->com. -- https://mail.python.org/mailman/listinfo/python-list
Re: translating foreign data
On Thu, 21 Jun 2018 10:12:27 -0700, Ethan Furman wrote: > I need to translate numeric data in a string format into a binary > format. I know there are at least two different methods of > representing parts less that 1, such as "10.5" and "10,5". The data > is encoded using code pages, and can vary depending on the file being > read (so I can't rely on current locale settings). > > I'm sure this is a solved problem, but I'm not finding those > solutions. Any pointers? Do you also have to accommodate the possibility that one thousand might be written "1,000" or "1.000"? -- To email me, substitute nowhere->runbox, invalid->com. -- https://mail.python.org/mailman/listinfo/python-list
Morning after
As if in a wake for Guido, grief was grieved, drinks were drunk, voices were raised, and some furniture was broken. Now, please, let's resume being the most civil newsgroup on the net. -- To email me, substitute nowhere->runbox, invalid->com. -- https://mail.python.org/mailman/listinfo/python-list
Re: What is the pattern for this number set?
On Wed, 18 Jul 2018 17:16:21 -0400, no@none.invalid wrote: [snip] > Anyone care to figure out the pattern and make a new copy of the > chart? > > https://imgur.com/a/thF6U43 I've only looked at infantry and carrier, but those two seem to be fairly well approximated by y = a + 1/(b*x + c), for a, b, and c being chosen individually for infantry and carrier. -- To email me, substitute nowhere->runbox, invalid->com. -- https://mail.python.org/mailman/listinfo/python-list
Re: curses, ncurses or something else
On Mon, 23 Jul 2018 23:24:18 +0100, John Pote wrote: > I recently wrote a command line app to take a stream of numbers, do some > signal processing on them and display the results on the console. There > may be several output columns of data so a title line is printed first. > But the stream of numbers may be several hundred long and the title line > disappears of the top on the console. > > So I thought it might be quick and easy to do something with curses to > keep the title line visable while the numbers roll up the screen. But > alas I'm a Windows user and the 'curses' module is not in the Windows > standard library for Python. > > It occured to me that I could create a simple tkinter class but I > haven't tinkered for some time and would have to refresh my knowledge of > the API. Just wondered if there was any other simple way I could keep > the title line on the console, preferably without having to install > another library. Browsergui is designed to simplify GUI-building by mooching off your web browser. I like it. sudo pip3 install browsergui python3 -m browsergui.examples Enjoy! -- To email me, substitute nowhere->runbox, invalid->com. -- https://mail.python.org/mailman/listinfo/python-list
Re: zpifile.py error - no crc 32 attribute
On Wed, 22 Aug 2018 13:12:59 +0200, jacob m wrote: [snip] > That's my error: > "import zipfile > File "/home/lib/python3.7/lib/python3.7/zipfile.py", line 19, in > crc32 = zlib.crc32 > AttributeError: module 'zlib' has no attribute 'crc32' " > > I have no idea what to do with that :/ I use this version of zipfile: > https://github.com/python/cpython/blob/3.7/Lib/zipfile.py > > Somebody knows how to solve it? zipfile imports zlib and expects zlib to define something called crc32. On your system, for some reason, the zlib that's being imported doesn't define anything called crc32. Is there perhaps a different zlib on your path, hiding the real zlib? -- 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 Fri, 31 Aug 2018 08:36:52 -0600, Malcolm Greene wrote: > I have use case where I need to distribute binary files to customers and > want to provide a way for our customers to verify the > "integrity/lineage" (I know there's a better description, but can't > think of it) of these files, eg. to give them the confidence that the > files in question are from me and haven't been altered. [snip] This is exactly what digital signatures are for. GPG is free, and will serve as well as anything. Generate a public/private key pair, email the public key to the customer, and phone the customer to compare key "fingerprints" to verify that the key hasn't been altered in transit (very unlikely, but cryptologists are a cautious bunch). Just using HMAC requires sharing a secret with the customer, which means that you have to trust the customer not to forge authentications. A real digital signature avoids this problem by separating the signing key (your private key) from the verifying key (the public key). -- 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 Fri, 31 Aug 2018 12:51:58 -0600, Malcolm Greene wrote: > Thanks for the replies! I'm going to investigate the use of > python-gnupg which is a Python wrapper for the GPG command line > utility. This library is based on gpg.py written by Andrew Kuchling. > I'm all ears if f anyone has any alternative recommendations or > python-gnupg tips to share. BTW: Target clients are running under > Windows and Linux. Writing your own crypto software is fraught with peril, and that includes using existing libraries. If you don't expect your system to get serious attention from a competent adversary, then fine, go ahead. No ... not even that. If you're _quite_confident_ that your system will never get serious attention ... go ahead. But if you think your system might someday be attacked by an adversary who will exploit insufficiently unguessable nonces, or accidental nonce re-use, or swap-space images of your executing code, or side channels, or any of the other hundreds of issues that have left the history of cryptography so entertainingly littered with the bodies of brilliant aspirants, . . . then use a much-studied, time-tested product. Don't take my word for it (retired cryptologist), ask any reputable cryptologist. Or ask on the sci.crypt newsgroup; they need some traffic. -- To email me, substitute nowhere->runbox, invalid->com. -- https://mail.python.org/mailman/listinfo/python-list
Re: Help Needed : script weird result.
On Sat, 1 Sep 2018 10:11:59 -0700 (PDT), moha...@gmail.com wrote: > All, > > I m trying to run this small script to find the lowest of the given > array of numbers. The script works fine for various combination of > inputs but fails in a weird way for a particular set of inputs, can > anyone point the mistake in the script and the behavior. > > Script > > x = input ("Enter the numbers separated by space and press ENTER :") > x = x.split(" ") > > def checkmin(arr): > lowest = arr[0] > for count in range(0,len(arr),1): > if arr[count] < lowest : > lowest = arr[count] > else : > pass > print (lowest) > return lowest > > minimum = checkmin(x) > print ("Lowest : {0}".format (minimum)) > > > Weird output is as below. > >== RESTART: C:\Users\mohan\Desktop\temp.py == > Enter the numbers separated by space and press ENTER :5 90 63 82 59 24 > 5 > 5 > 5 > 5 > 5 > 24 > Lowest : 24 Assuming this is homework, here's a hint: Instead of "5 90 63 82 59 24", feed it "2 ", or "1 09" or "1 2 3 ." (yes, "."). As a stylistic matter, looping over an array's indices is more cumbersome than looping over the elements of the array ("for x in arr:"), unless you actually need the index for something, which you don't. Also, two of the three arguments you pass to range can be omitted. -- To email me, substitute nowhere->runbox, invalid->com. -- 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
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: 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 = ( '==', 'îÖî±î½î¿ïàî¬ïüî1î¿ ... > years = ( '=', 2010, 2011, 2012, 2 ... > > > pdata = pdata + ''' > îòï î1î»îµîºïäî1îºîR îæî½î±î¶îRïäî·ïâî·: > > > %s > > > > %s > > > > %s > > > > ''' % ( 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
Re: perplexing error
On 8 Sep 2018 17:25:52 GMT, Stefan Ram wrote: > Sharan Basappa writes: >> 66 # get the label for each log >> 67 data_df['label'] = (data_df['label'] != '-').astype(int) >>---> 68 #logger.debug("data frame %s \n", data_df) >> 69 logger.debug("\n") >> 70 raw_data = data_df[['label','seconds_since']].as_matrix() >>AttributeError: 'str' object has no attribute 'raw_data' >>If you notice, line 68 is commented. >>I am not sure what I am doing wrong. > > In such cases, I do: > > print( 'at position 1' ) > data_df['label'] = (data_df['label'] != '-').astype(int) > print( 'at position 2' ) > raw_data = data_df[['label','seconds_since']].as_matrix() > print( 'at position 3' ) > > . If the last text printed is "at position 1", I will then > split even more: > > print( 'at position 1' ) > tmp = (data_df['label'] != '-').astype(int) > print( 'at position 1a' ) > data_df['label'] = tmp > print( 'at position 2' ) > raw_data = data_df[['label','seconds_since']].as_matrix() > print( 'at position 3' ) > > and so on until the cause is reduced to the smallest > possible unit of code. This approach is especially valuable when it turns out that the file you're editing is not the file being included. -- To email me, substitute nowhere->runbox, invalid->com. -- https://mail.python.org/mailman/listinfo/python-list
Re: perplexing error
On 8 Sep 2018 19:10:09 GMT, Stefan Ram wrote: > Peter Pearson writes: >>On 8 Sep 2018 17:25:52 GMT, Stefan Ram wrote: >>>In such cases, I do: >>>print( 'at position 1' ) >>This approach is especially valuable when it turns out that >>the file you're editing is not the file being included. > > I am not sure whether this is taken to be literally or as > being sarcastic. [snip] No sarcasm intended. I've made the editing-wrong-file goof many times. -- To email me, substitute nowhere->runbox, invalid->com. -- https://mail.python.org/mailman/listinfo/python-list
Re: Python Probability
On Tue, 11 Sep 2018 20:54:23 +0200 (CEST), Bat erdene endzis wrote: [snip] > def dice(): > attacker_dice=[random.randint(1,6) for _ in range(3)] > defender_dice=[random.randint(1,6) for _ in range(2)] > a=max(attacker_dice) > b=max(defender_dice) > for i in range(1000): > F=0 > S=0 > T=0 > if a>b: > F+=1 > if a==b: > S+=1 > else: > T+=1 Do you really want to set F, S, and T back to zero on each pass through that loop? Presumably you want to remove a from attacker_dice and b from defender_dicce and repeat the comparison with the new maxes. -- To email me, substitute nowhere->runbox, invalid->com. -- https://mail.python.org/mailman/listinfo/python-list
Re: GUI, Python2.7- how to build a loop with a button + textbox
On Tue, 11 Sep 2018 19:51:01 -0700 (PDT), alon.naj...@gmail.com wrote: > hi, > > on python 2.7 how do I build a loop with a button + textbox? > > for example: > > I want the user to enter is name and then press "ok" button, I want > his name to be printed 5 times. Tested on Python 3.5.3: import browsergui as bg def button_clicked(): for i in range(5): print(text_field.value) text_field = bg.TextField() bg.GUI(text_field, bg.Button("OK", callback=button_clicked)).run(quiet=True) If you don't have browsergui, "pip install browsergui". -- To email me, substitute nowhere->runbox, invalid->com. -- https://mail.python.org/mailman/listinfo/python-list
Re: JPEGImage() hangs
On Fri, 28 Sep 2018 15:01:41 +0100, Chris Green wrote: > Chris Green wrote: >> Brian Oney wrote: >> > Could you please try another tool like `convert'? E.g. >> > >> > $ convert 102_PANA/P1020466.JPG test.png >> > >> > >> > What does that say? >> >> Well, after having returned home with the laptop where this was >> failing and doing exactly the same thing again, it now works. However >> it did take several seconds before the >>> prompt appeared. >> >> The problem seems to be intermittent as I'm calling the function while >> importing images from a camera SD card and, sometimes, the import >> hangs but most times it works OK. >> >> I'll see if I can see anything common to when it hangs. >> > ... and the result is that it now hangs several images later in the > sequence! It's almost as if some resource is running out. > > If I try convert on the 'problem' image it too hangs absolutely > solidly needing a 'kill -9'. > > After some experimentation OK, it's some sort of file > accessibility problem between the SD card and the computer:- > > Running 'convert 102_PANA/P1020493.JPG /tmp/xyz.png' hangs > > So 'kill -9' the convert > > Run 'cp 102_PANA/P1020493.JPG /tmp/fred' takes several seconds but returns [snip] If copying that particular file takes longer than copying other files, I'd start to suspect that it's stored in a failing spot in memory. Is 102_PANA/P1020493.JPG being read from a camera's flash memory? Does "convert" hang on /tmp/fred? Does 102_PANA/P1020493.JPG have an unusual size? Can you use smartctl to ask the storage device if it's encountering many errors? -- To email me, substitute nowhere->runbox, invalid->com. -- https://mail.python.org/mailman/listinfo/python-list