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: 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: 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
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: 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
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: 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 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: "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: 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: 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: 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: 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: How to copy the entire outlook message content in python
On Tue, 29 Dec 2020 05:38:53 -0800 (PST), nikhil k wrote: ...[snip]... > import win32com.client as win32 > > ### Functions > def getMailBody(msgFile): > start_text = "" > end_text = "" > with open(msgFile) as f: > data=f.read() > return data[data.find(start_text):data.find(end_text)+len(end_text)] ...[snip]... > > > Below is the error I'm getting. >== > File "C:\Python\Python38-32\lib\encodings\cp1252.py", line 23, in decode > return codecs.charmap_decode(input,self.errors,decoding_table)[0] > UnicodeDecodeError: 'charmap' codec can't decode byte 0x81 in position 924: > character maps to I'm not completely sure that it's the f.read() call that produces the error, because you cut out the earlier lines of the error message, but . . . I think the problem is that the data in the file you're reading do not represent a valid "encoding" of any character string, using whatever encoding convention Python thinks you want to use. Maybe Python is assuming you're using ASCII encoding; 0x81 is certainly not a valid ASCII character. I don't know how Outlook represents messages in its .msg files; it's possible it packs ASCII text along with binary data. Maybe you can find a Python package that reads .msg files. Maybe you could read the file as a bytestring instead of as a character string. -- To email me, substitute nowhere->runbox, invalid->com. -- https://mail.python.org/mailman/listinfo/python-list
Re: 2 sample chi-square test
On Tue, 29 Dec 2020 02:52:15 -0800 (PST), Priya Singh wrote: [snip] > I have two spectra with wavelength, flux, and error on flux. I want to > find out the variability of these two spectra based on the 2 sample > Chi-square test. I am using following code: > > def compute_chi2_var(file1,file2,zemi,vmin,vmax): > w1,f1,e1,c1,vel1 = get_spec_vel(dir_data+file1,zemi) > id1 = np.where(np.logical_and(vel1 >= vmin, vel1 < vmax))[0] > w2,f2,e2,c2,vel2 = get_spec_vel(dir_data+file2,zemi) > id2 = np.where(np.logical_and(vel2 >= vmin, vel2 < vmax))[0] > f_int = interp1d(w1[id1], f1[id1]/c1[id1], kind='cubic') > e_int = interp1d(w1[id1], e1[id1]/c1[id1], kind='cubic') > f_obs,e_obs = f_int(w2[id2]), e_int(w2[id2]) > f_exp, e_exp = f2[id2]/c2[id2], e2[id2]/c2[id2] > e_net = e_obs**2 + e_exp**2 > chi_square = np.sum( (f_obs**2 - f_exp**2)/e_net ) > dof = len(f_obs) - 1 > pval = 1 - stats.chi2.cdf( chi_square, dof) > print('%.10E' % pval) > > NN = 320 > compute_chi2_var(file7[NN],file14[NN],zemi[NN],vmin[NN],vmax[NN]) > > > I am running this code on many files, and I want to grab those pair of > spectra where, the p-value of chi-squa is less than 10^(-8), for the > change to be unlikely due to a random occurrence. > > Is my code right concept-wise? Because the chi-squ value is coming out > to be very large (positive and negative), such that my p-value is > always between 1 and 0 which I know from other's results not correct. > > Can anyone suggest me is the concept of 2-sample chi-squ applied by me > is correct or not? 1. This is not really a Python question, is it? 2. Recommendation: test your chi-squared code on simpler sample data. 3. Observation: P-values *are* normally between 0 and 1. 4. Observation: chi-squared values are never negative. 5. Recommendation: Learn a little about the chi-squared distribution (but not on a Python newsgroup). The chi-squared distribution with N degrees of freedom is the distribution expected for a quantity that is the sum of the squares of N normally distributed random variables with mean 0 and standard deviation 1. If you expect f_obs to equal f_exp plus some normally distributed noise with mean 0 and standard deviation sigma, then (f_obs-f_exp)/sigma should be normally distributed with mean 0 and standard deviation 1. 6. Observation: (f_obs**2 - f_exp**2)/e_net is probably not what you want, since it can be negative. You probably want something like (f_obs-f_exp)**2/e_net. But don't take my word for it. Good luck. -- To email me, substitute nowhere->runbox, invalid->com. -- https://mail.python.org/mailman/listinfo/python-list
Re: EnvironmentError
On Thu, 19 Nov 2020 13:19:07 +0100, Usman Musa wrote: > When I try to install a package or upgrade pip, using pip install I got > this error massage. > WARNING: Retrying (Retry(total=4, connect=None, read=None, > redirect=None, status=None)) after connection broken by > 'SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] > certificate verify failed: certificate is not yet valid (_ssl.c:1122)'))': [snip] > Please help me out Just guessing, here. Might "not yet valid" mean that your computer's clock is set to 1970? Is there any indication *whose* certificate is "not yet valid"? E.g., some URL from which pip is trying to load things? -- To email me, substitute nowhere->runbox, invalid->com. -- https://mail.python.org/mailman/listinfo/python-list
Re: returning totals in functions of math
On Sun, 8 Nov 2020 13:50:19 -0500, Quentin Bock wrote: > Errors say that add takes 1 positional argument but 3 were given? Does this > limit how many numbers I can have or do I need other variables? > Here is what I have: > def add(numbers): >total = 1 >for x in numbers: > total += x >return total > print(add(1999, -672, 84)) Your function "add" expects a single argument that is a list of numbers. You're passing it three arguments, each a number. Try add([1999, -672, 84]). -- To email me, substitute nowhere->runbox, invalid->com. -- https://mail.python.org/mailman/listinfo/python-list
Re: Is there a conflict of libraries here?
On Fri, 6 Nov 2020 02:25:25 -0500, Steve wrote: > In my program, I have the following lines of code: > import random > import re > import time > import datetime At this point, the name "datetime" points to a module. > from datetime import timedelta > from time import gmtime, strftime > import winsound as ws > import sys > [snip] > > from datetime import datetime By that, you have reassigned the name "datetime" to point to a class defined in the datetime module. [snip] > > AttributeError: type object 'datetime.datetime' has no attribute > 'datetime' Right, because the name "datetime" points to the class datetime in the module datetime. The class, unlike the module, has no "datetime" attribute. Apologies if you already knew this. I wasn't sure. -- To email me, substitute nowhere->runbox, invalid->com. -- https://mail.python.org/mailman/listinfo/python-list
Re: Best way to determine user's screensize?
On Sun, 1 Nov 2020 15:31:57 - (UTC), Grant Edwards wrote: > > I have no objection to saving the most recent window size and using > that on the next startup, but I hate applications that force the > _location_ of the window. I've configured my window manager to open > windows where I want them opened, please respect that. Hear, hear! This user has invested a lot of time learning how to live comfortably with his window manager. When some upstart app invalidates that knowledge and the corresponding deeply ingrained habits, it's a big annoyance. -- To email me, substitute nowhere->runbox, invalid->com. -- https://mail.python.org/mailman/listinfo/python-list
Re: Problem saving datetime to file and reading it back for a calculation
On Sat, 10 Oct 2020 18:17:26 -0400, Steve wrote: > I would like to use the line: > HoursDiff = int((d2-d1).total_seconds()/3600) > to determine the difference in hours between two timedate entries. > > The variable d2 is from datetime.now() > and d1 is read from a text file. > > I can save d2 to the file only if I convert it to string and, at a later > date, it gets read back in as d1 as string. The variable d1 as string will > not work in the HoursDiff statement. > > To me, it looks like a problem in formatting. > How do I fix this? datetime.datetime.strftime and datetime.datetime.strptime ? >>> t = datetime.datetime.now() >>> t.strftime("%Y-%m-%d %H:%M:%S") '2020-10-10 18:02:33' >>> b = datetime.datetime.strptime("2020-09-09 12:34:56", "%Y-%m-%d %H:%M:%S") >>> b.strftime("%Y-%m-%d %H:%M:%S") '2020-09-09 12:34:56' >>> -- To email me, substitute nowhere->runbox, invalid->com. -- https://mail.python.org/mailman/listinfo/python-list
Python's carbon guilt
Python advocates might want to organize their thoughts on this subject before their bosses spring the suggestion: >From >https://www.sciencemag.org/news/2020/10/we-re-part-problem-astronomers-confront-their-role-and-vulnerability-climate-change > : . . . Astronomers should also abandon popular programming languages such as Python in favor of efficient compiled languages. Languages such as Fortran and C++, Zwart calculates, are more than 100 times more carbon efficient than Python because they require fewer operations. -- To email me, substitute nowhere->runbox, invalid->com. -- https://mail.python.org/mailman/listinfo/python-list
Re: Truncation error
On Wed, 7 Oct 2020 13:29:26 +0530, Meghna Karkera wrote: > On Wed, Oct 7, 2020, 11:24 Marco Sulla wrote: >> On Wed, 7 Oct 2020 at 05:23, Meghna Karkera wrote: >> > >> > How is PYTHON better than other software's(MATLAB) in case of >> > truncation or rounding off error. > >> [snip] > > When I use the same code in MATLAB I get the answer as 4.6e-06 and when I > use the same code in PYTHON I get the answer as 4.7e-06. How do I know > which is the most precise and accurate value. Actually the answer is a big > matrix, I've only compared the first entry of the matrix. I hope your big matrix has many elements much larger than 4.7e-06, so that you don't really have to worry about which package has the smaller roundoff error. If you *are* in the situation of having to worry about roundoff error, that's likely to mean that you have to plan your entire computation around the goal of minimizing its susceptibility to tiny amounts of noise, and that's a problem much more complex than choosing a language. -- To email me, substitute nowhere->runbox, invalid->com. -- https://mail.python.org/mailman/listinfo/python-list
Re: ValueError: arrays must all be same length
On Fri, 2 Oct 2020 13:34:46 +0100, Shaozhong SHI wrote: > Hello, > > I got a json response from an API and tried to use pandas to put data into > a dataframe. > > However, I kept getting this ValueError: arrays must all be same length. > > Can anyone help? > > The following is the json text. Regards, Shao > > { > "locationId": "1-1004508435", > "providerId": "1-101641521", ... [huge block removed] ... > "reportType": "Location" > } > ] > } > > In [ ]: > > > In [25]: > j > > > import pandas as pd > > import json > > j = json.JSONDecoder().decode(req.text) ###req.json > > df = pd.DataFrame.from_dict(j) An important programming skill is paring back failing code to create the smallest example that exhibits the failure. Often, the paring process reveals the problem; and if it doesn't, the shorter code is more likely to attract help. -- To email me, substitute nowhere->runbox, invalid->com. -- https://mail.python.org/mailman/listinfo/python-list
Re: news.bbs.nz is spewing duplicates to comp.lang.python
On Tue, 21 Apr 2020 21:42:42 + (UTC), Eli the Bearded wrote: > This just arrived at my newserver: > > Path: > reader2.panix.com!panix!goblin2!goblin.stu.neva.ru!news.unit0.net!2.eu.feeder.erje.net!4.us.feeder.erje.net!feeder.erje.net!xmission!csiph.com!news.bbs.nz!.POSTED.agency.bbs.nz!not-for-mail > From: Eli the Bearded <*@eli.users.panix.com> (Eli the Bearded) > Newsgroups: comp.lang.python > Subject: Re: Getting a 401 from requests.get, but not when logging in via > the br > Date: Mon, 20 Apr 2020 19:18:48 +1200 > Organization: fsxNet Usenet Gateway | bbs.nz/#fsxNet > Message-ID: <3057175...@f38.n261.z1.binkp.net> > References: <1492048...@f38.n261.z1.binkp.net> > Mime-Version: 1.0 > Content-Type: text/plain; charset=us-ascii > Content-Transfer-Encoding: 7bit > Injection-Info: news.bbs.nz; > posting-host="8IWYKlztXHa0+IViEdY46zrq8kpk7dC9fTbT74JiSDQ"; > logging-data="12595"; mail-complaints-to="ab...@news.bbs.nz" > User-Agent: VSoup v1.2.9.47Beta [95/NT] > X-Comment-To: dcwhatthe > X-MailConverter: SoupGate-Win32 v1.05 > Lines: 36 > > I find that very curious because the post is mine but which I > sent out with these headers: > > Path: reader2.panix.com!panix!qz!not-for-mail > From: Eli the Bearded <*@eli.users.panix.com> > Newsgroups: comp.lang.python > Subject: Re: Getting a 401 from requests.get, but not when logging in via > the browser. > Date: Mon, 20 Apr 2020 19:18:48 + (UTC) > Organization: Some absurd concept > Lines: 37 > Message-ID: > References: <48a2e19c-0a52-4cfa-b498-15e3d15b6...@googlegroups.com> > NNTP-Posting-Host: panix5.panix.com > X-Trace: reader2.panix.com 1587410328 23363 166.84.1.5 (20 Apr 2020 > 19:18:48 GMT) > X-Complaints-To: ab...@panix.com > NNTP-Posting-Date: Mon, 20 Apr 2020 19:18:48 + (UTC) > X-Liz: It's actually happened, the entire Internet is a massive game of > Redcode > X-Motto: "Erosion of rights never seems to reverse itself." -- kenny@panix > X-US-Congress: Moronic Fucks. > X-Attribution: EtB > XFrom: is a real address > Encrypted: double rot-13 > User-Agent: Vectrex rn 2.1 (beta) > > The timezone on the date header has changed, the subject has been > truncated, the Path and injection info is all different, and most > crucially, the MESSAGE-ID and REFERENCES are completely bogus. > News servers rely on Message-ID to tell if a message is unique. Change > it, and it is now a new message. Screwing up References: header while > changing the Subject: is going to break news threading. [snip] Thank you for bringing this up. I thought I was going crazy. -- To email me, substitute nowhere->runbox, invalid->com. -- https://mail.python.org/mailman/listinfo/python-list
Re: Help building python application from source
On Fri, 28 Feb 2020 18:49:58 -0800, Mr. Lee Chiffre wrote: [snip] > I am a python noob. This is why I ask the python masters. There is a > python software I want to install on the server it is called Electrumx. > https://github.com/kyuupichan/electrumx is the link. I am having troubles > with installing this. > The short version is I am wanting to build this python application and > needed dependencies from source code all from a local directory without > relying on the python pip package servers. I only run software I can > compile from source code because this is the only way to trust open source > software. I also want to archive the software I use and be able to install > it on systems in a grid down situation without relying on other servers > such as python package servers. (To make OP's requirements plainly visible, note that this appears to be a cryptocurrency application.) I'd suggest that building everything from source code might not be a realistic solution to your security concerns. I don't know what your threat model is, but if it's something like, "Hackers and gangsters who scatter password-harvesting trojans across the globe and then shlurp up what they can," you might find that you get better security by generating your keys on a computer that never communicates with the outside world. Your concerns are (1) that the random numbers from which your keys have been corrupted to make them predictable, or (2) that malicious software will send your keys to the bad guys. Isolating the key-generation machine takes care of #2. If you have Python code for generating keys, something as simple as XORing a fixed value of your choice with its random numbers will take care of #1. I admit that using an isolated machine introduces a lot of inconveniences, but I bet it compares favorably with building everything from source. -- To email me, substitute nowhere->runbox, invalid->com. -- https://mail.python.org/mailman/listinfo/python-list
Re: fugacity cofficient
On 17 Feb 2020 18:40:00 GMT, Peter Pearson wrote: > > Welcome, Alberto. > > Can you make this look more like a Python question and less like a > do-my-homework question? Show us what you've tried. Sorry. I see you already did exactly that. -- To email me, substitute nowhere->runbox, invalid->com. -- https://mail.python.org/mailman/listinfo/python-list
Re: fugacity cofficient
On Sun, 16 Feb 2020 14:17:28 -0800 (PST), alberto wrote: > Hi, > how I could realize a script to calculate fugacity coefficients > with this formula > [snip] > > regards > > Alberto Welcome, Alberto. Can you make this look more like a Python question and less like a do-my-homework question? Show us what you've tried. -- To email me, substitute nowhere->runbox, invalid->com. -- https://mail.python.org/mailman/listinfo/python-list
Re: Help
On Sun, 12 Jan 2020 22:23:58 +0530, kiran chawan wrote: > Whenever Iam trying to run this 'New latest version python software 3.8.4 > python ' but it doesn't show any install option tell me how to run this > software and install new latest version of python plz reply sir thank you To get a useful answer, you'll need to provide more information. What operating system are you running? Is there already some kind of Python environment on your machine? Have you downloaded some specific Python file that you're trying to run? Where did you get it? -- To email me, substitute nowhere->runbox, invalid->com. -- https://mail.python.org/mailman/listinfo/python-list
Re: Complaints on installing packages
On Sun, 12 Jan 2020 15:21:52 +0100, ofomi matthew wrote: > Good day Python Team, > I'm Matt by name and I have been having difficulties in installing packages > on my pycharm.it keeps telling me "error installing package". Please how do > I rectify this issues step by step. > Looking forward to get a response as soon as possible. Thank you Welcome, Matt. Your chances of getting an answer to your question would be much improved if you included more information. What is the package that is being installed? What command did you issue? Was there any additional information besides "error installing package"? -- To email me, substitute nowhere->runbox, invalid->com. -- https://mail.python.org/mailman/listinfo/python-list
Re: Randomizing Strings In A Microservices World
On Mon, 9 Dec 2019 21:38:43 -0600, Tim Daneliuk wrote: > On 12/9/19 8:54 PM, Dennis Lee Bieber wrote: >> On Mon, 9 Dec 2019 18:52:11 -0600, Tim Daneliuk >> declaimed the following: >> >>> - Each of these services needs to produce a string of ten digits >>> guaranteed to be unique on a per service instance basis AND to not >>> collide for - oh, let's say - forever :)s >>> >>> Can anyone suggest a randomization method that might achieve this >>> efficiently? >>> >>> My first thought was to something like nanonseconds since the epoch >>> plus something unique about the service instance - like it's IP? >>> (This is in a K8s cluster) - to see the randomization and >>> essentially eliminate the string being repeated. >>> >>> Ideas welcome .. >> >> Well, 10 digits is rather short, but studying >> https://en.wikipedia.org/wiki/Universally_unique_identifier might provide >> some ideas. > > For a variety of reasons the length of this string cannot exceed 10 > digits. It is believed that - in this application - the consumption > of values will be sparse over time. All I really need is a high > entropy way to select from among the billion possible values to > minimize the possibility of collisions (which require retry and time > we don't want to burn). Just to be sure: you *are* aware that the "Birthday Paradox" says that if you pick your 10-digit strings truly randomly, you'll probably get a collision by the time of your 10**5th string . . . right? -- To email me, substitute nowhere->runbox, invalid->com. -- https://mail.python.org/mailman/listinfo/python-list
Re: graphics with python
On Thu, 24 Oct 2019 16:06:21 +0800, Maggie Q Roth wrote: [snip] > Can you show me the correct way to programming with graphics? > > I want to take some action detection, for instance, recognize dancing etc. That description of your goals is very vague. The more specific you can be about what you want to do, the more likely you are to get a helpful response. "Programming with graphics" sounds like drawing charts, or graphs, or pictures, or games. "Recognize dancing etc." sounds like image processing, maybe involving huge neural networks. The most useful thing you could provide would be a statement of the form, "I want to produce software that will take X as input and produce output Y." -- To email me, substitute nowhere->runbox, invalid->com. -- https://mail.python.org/mailman/listinfo/python-list
Re: Hello, I need help.
On Tue, 15 Oct 2019 18:57:04 +0300, Damla Pehlivan wrote: [snip] > . . . I downloaded the python program, and I > also downloaded Pycharm to use it. To be fair, I do not know what I am > doing, but I made some progress last night and I was happy about it. Today > when I came back from university, I realised the program was updated, I > updated it and now I cannot use it. When I clicked on it, it kept opening > the modify tab. I did modify it and repaired it. But it kept not opening > the actual program. A clearer description of your situation would improve your odds of getting a useful result. For starters, what operating system are you using? What application presents the "modify tab" that you mention? Is this perhaps a problem with your software-installing process, rather than with Python or with Pycharm? Have you found a good Python tutorial? -- To email me, substitute nowhere->runbox, invalid->com. -- https://mail.python.org/mailman/listinfo/python-list
Re: Angular distribution rose diagram in Python
On Fri, 27 Sep 2019 02:13:31 -0700 (PDT), Madhavan Bomidi wrote: > > Can someone help me to make python code (with some arbitrary data) for > the angular distribution rose diagram as shown in figure 7 in the > paper accessible through the web-link: > > https://www.nat-hazards-earth-syst-sci.net/17/1425/2017/nhess-17-1425-2017.pdf Googling "matplotlib rose diagram" (without the quotation marks) produced some promising results. This one even has sample code: http://geologyandpython.com/structural_geology.html I'm no graphics expert, but Matplotlib generally does the job for me. -- To email me, substitute nowhere->runbox, invalid->com. -- https://mail.python.org/mailman/listinfo/python-list
Re: Xlabel and ylabel are not shown
On Sat, 17 Aug 2019 10:58:43 -0700 (PDT), Amirreza Heidari wrote: > plt.figure(1) > plt.plot(history.history["loss"], "b", label="Mean Square Error of training") > plt.plot(history.history["val_loss"], "g", label="Mean Square Error [snip] > plt.legend() > plt.xlabel("Epoche") > plt.ylabel("Mean Square Error") > plt.xlim(0,200) > plt.show() > plt.savefig(r"C:\Users\aheidari\Dropbox\Dissertation\primary hot [snip] It works for me (using simple, fake data points, of course). Perhaps you could tell us which versions of Python and matplotlib you're using? -- To email me, substitute nowhere->runbox, invalid->com. -- https://mail.python.org/mailman/listinfo/python-list
Re: Creating time stamps
On Mon, 22 Jul 2019 16:25:32 -0500, Michael F. Stemper wrote: > On 22/07/2019 15.58, Chris Angelico wrote: >> On Tue, Jul 23, 2019 at 6:34 AM Michael F. Stemper >> wrote: >>> [snip] >>> from datetime import datetime >>> from time import strftime >>> timestamp = datetime.now().strftime( "%Y-%m-%d %H:%M" ) [snip] >> >> What's the second import doing though? You never use strftime. > > Cleaned my contacts, cleaned my readers. Still see strftime() in the > third line. Tried to run the code without the second line. It ran > without complaint. > > Apparently, the strftime() in that last line is not the one that I > explicitly imported, but a method of datetime.now(). Did I get that > right? Yes, you got that right. The statement datetime.now().strftime("...") says that datetime.now will return an object that has a method named strftime, and calling that method is the next thing to be done. Other things that happen to be lying around named strftime just have no part in the conversation. -- To email me, substitute nowhere->runbox, invalid->com. -- https://mail.python.org/mailman/listinfo/python-list
Re: How to sort the files based on the date?
On Mon, 15 Jul 2019 09:20:51 +0200, Peter Otten <__pete...@web.de> wrote: > Madhavan Bomidi wrote: > [snip] >> >> 3RIMG_01APR2018_0514_L2G_AOD.h5 >> 3RIMG_01APR2018_0544_L2G_AOD.h5 >> 3RIMG_01APR2018_0644_L2G_AOD.h5 >> 3RIMG_01APR2018_0714_L2G_AOD.h5 >> 3RIMG_01APR2018_0744_L2G_AOD.h5 [snip] >> >> Can anyone suggest me how I can sort theses files in increasing order of >> the date on the file name? > > Use a key function > > filenames = sorted(filename, key=get_datetime) > > get_datetime should extract date/time from the filename into a datetime > object. The names will then be ordered according to the datetimes' values: > > import glob > import datetime > > def get_datetime(filename): > parts = filename.split("_") > return datetime.datetime.strptime(parts[1] + parts[2], "%d%b%Y%H%M") > > filenames = sorted(glob.glob('3RIMG_*.h5'), key=get_datetime) > > for fn in filenames: > print(fn) Gorgeous. This is the best newsgroup ever. -- To email me, substitute nowhere->runbox, invalid->com. -- https://mail.python.org/mailman/listinfo/python-list
Re: Seeking help regarding Python code
On Thu, 11 Jul 2019 06:54:21 +0100, Debasree Banerjee wrote: > > I have a dataset like this: > > RecTime > > NO2_RAW > > NO2 > > LAQN_NO2 > > 10980 > > 06/6/19 01:45 > > 17.9544 [snip] > > Can someone please help? Your question might appear intelligibly on the mailing list (I can't tell), but it is mangled into unintelligibility on the newsgroup. My guess is that instead of double-spaced mixed-type data fields, you intended to present an input table like this: RecTime NO2_RAW NO2 LAQN_NO2 10980 06/6/19 01:45 17.9544 53.4626 17.7 10981 06/6/19 01:45 17.9444 53.4434 17.7 10982 06/6/19 01:45 17.9211 53.3988 17.7 I really can't tell what you want the output to look like. -- To email me, substitute nowhere->runbox, invalid->com. -- https://mail.python.org/mailman/listinfo/python-list
Re: finding a component in a list of pairs
[snip] > print( dict( pairs ).get( 'sun', '(unknown)' )) You probably know this, but . . . just in case . . . If you're doing this many times, you'll want to construct the dict just once and then make many references to the dict, rather than re-constructing the dict every time you want to look up an element. -- To email me, substitute nowhere->runbox, invalid->com. -- https://mail.python.org/mailman/listinfo/python-list
Re: finding a component in a list of pairs
On 22 Jun 2019 13:24:38 GMT, Stefan Ram wrote: [snip] > > print( next( ( pair for pair in pairs if pair[ 0 ]== 'sun' ), > ( 0, '(unbekannt)' ))[ 1 ]) > print( next( itertools.dropwhile( lambda pair: pair[ 0 ]!= 'sun', pairs )) > [ 1 ]) [snip] > > The last two lines of the program show two different > approaches to search for the translation of »sun«. > > Which approach is better? Or, do you have yet a better idea > about how to find the translation of »sun« in »pairs«? Are you allowed to use a dict? -- To email me, substitute nowhere->runbox, invalid->com. -- https://mail.python.org/mailman/listinfo/python-list
Re: Why am a getting wrong prediction when combining two list of samples, which individually gives correct prediction?
On Wed, 12 Jun 2019 04:12:34 -0700 (PDT), Rishika Sen wrote: > So I am coding in Python. I have to set of samples. Set1 contains > samples of class A and the other set, Set2 contains samples of class > B. When I am predicting set1 and set2 individually, the classification > is perfect. Now when I am merging the two sets for prediction into one > set, the prediction gives the wrong result for the samples in Set2, > i.e., predicting the samples of set 2 to be in class A. However, > samples belonging to Set1 are predicted to be in class A in the merged > set. Why is this happening? > > model.add(Dense(newshape[1]+1, activation='relu', input_shape=(newshape[1],))) > model.add(Dropout(0.5)) > model.add(Dense(500, activation='relu')) > model.add(Dropout(0.5)) > model.add(Dense(250, activation='relu')) > model.add(Dropout(0.5)) > model.add(Dense(100, activation='relu')) > model.add(Dropout(0.5)) > model.add(Dense(50, activation='relu')) > model.add(Dropout(0.5)) > model.add(Dense(1, activation='sigmoid')) > model.compile(loss='binary_crossentropy', > optimizer='adam', > metrics=['binary_accuracy']) > model.fit(X_train, y_train,validation_data=(X_test, y_test), > validation_split=0.2, epochs=500, batch_size=25, verbose=0) This is really a question about some model-fitting package that you're using, not about Python. And you don't even tell us which model-fitting package it is. Please share more information. Are you expecting that any model-fitting process that works individually on Set1 and Set2 must work on the union of the two sets? 'Cause I don't think it works that way. -- To email me, substitute nowhere->runbox, invalid->com. -- https://mail.python.org/mailman/listinfo/python-list
Re: Read the table data from PDF files in Python
On Wed, 24 Apr 2019 02:36:27 -0700 (PDT), mrawat...@gmail.com wrote: > Hello, > Anyone knows how to fetch the data from PDF file having tables with > other text in Python. Need to fetch some cell values based on > condition from that table. You might find pdftotext useful. The command . . . pdftotext -layout somefile.pdf produces a file named somefile.txt. This will be completely useless if the original PDF is just a PDF wrapper around an image. That's what document scanners tend to produce. -- To email me, substitute nowhere->runbox, invalid->com. -- https://mail.python.org/mailman/listinfo/python-list
Re: Trying to read in data for a file to a python application
On Tue, 26 Feb 2019 15:51:38 +, Paul Sutton wrote: > Hi > > I have been trying to write a small application that is essentially user > information application. > > https://raw.githubusercontent.com/zleap/AboutMe/master/Aboutme.py > > So far I have managed to write the data generated to a file, what I want > to do now, is read this data back in when the user opens the program. > [snip] > > So far the GUI window appears but no widgets. So something is clearly > getting stalled. > > To begin with If I can read the text in, and just display in the console > this is a start, I can then see if I can figure out how to take that and > insert the data in to the right places. I'd suggest writing a terminal-based, non-GUI program to read your data file and do something simple with it like displaying it on the terminal. The strategy is to tackle your problem (reading back the data) in the simplest context possible. -- 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
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: 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: 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: 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: 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: 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 = ( '==', 'Ιανουάριο ... > 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: 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: 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: 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: 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: 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: 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
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: 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
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: 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: 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: 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: 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: 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: 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: 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: seeking deeper (language theory) reason behind Python design choice
On Wed, 09 May 2018 12:51:15 -0700, Paul Rubin wrote: > Dennis Lee Bieberwrites: >> 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: 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 <pkpearson@nowhere.invalid> > 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: checksum problem
On Tue, 30 Jan 2018 11:24:07 +0100, jakwrote: > 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 Sun, 28 Jan 2018 20:24:55 -0800, Dan Strombergwrote: [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: 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: 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: Python bug report
On Thu, 21 Dec 2017 23:54:17 +0100, Ranyawrote: > 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: 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: 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: Python Mailing list moderators
On Sun, 5 Nov 2017 17:28:05 -0500, Terry Reedywrote: > 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: Compression of random binary data
On Thu, 26 Oct 2017 19:26:11 -0600, Ian Kellywrote: > > . . . 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: 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: A Good Tutorial on Python Decorators
On Tue, 27 Jun 2017 16:43:38 +, Andre Müller wrote: > Peter Pearson <pkpearson@nowhere.invalid> schrieb am Di., 27. Juni 2017 um > 18:35 Uhr: > >> On Tue, 27 Jun 2017 15:10:53 + (UTC), Saurabh Chaturvedi wrote: >> > https://opensource.google.com/projects/py-decorators-tutorial >> >> "No Results found." >> > Activate JavaScript, then you can see the content. > I had the same problem. (Blushing) Thanks. Life is getting difficult for us JavaScript paranoids. -- To email me, substitute nowhere->runbox, invalid->com. -- https://mail.python.org/mailman/listinfo/python-list
Re: A Good Tutorial on Python Decorators
On Tue, 27 Jun 2017 15:10:53 + (UTC), Saurabh Chaturvedi wrote: > https://opensource.google.com/projects/py-decorators-tutorial "No Results found." -- To email me, substitute nowhere->runbox, invalid->com. -- https://mail.python.org/mailman/listinfo/python-list
Re: plot time on X axis
On Wed, 07 Jun 2017 09:20:25 -0300, jorge.conr...@cptec.inpe.br wrote: [snip] > I was an IDL user and I'm using Python. I have several meteorological > daily time seriee for several years. Please can someone help me. I would > like to plot on X axis only the values o the year. Is matplotlib allowed? Example (Python 2.7)(Note that most of this example is just parsing data, not plotting:): from matplotlib import pyplot as plt from datetime import date import re dwcd = """ 2014-06-01: 82.00% ( 1) 89.50% ( 2) 39.00% ( 1) 0.259 2014-07-01: 100.00% ( 1) 89.00% ( 3) 0.00% ( 1) 0.264 2014-08-01: 79.50% ( 2) 85.50% ( 4) 53.00% ( 1) 0.273 2014-09-01: 85.00% ( 3) 98.00% ( 6) 87.00% ( 3) 0.495 2014-10-01: 86.00% ( 7) 97.00% (10) 82.50% ( 4) 0.553 2014-11-01: 93.50% (10) 98.50% (10) 39.00% ( 6) 0.215 2014-12-01: 97.00% (10) 100.00% (10) 66.50% ( 6) 0.025 2015-01-01: 72.50% (12) 94.00% (11) 39.00% ( 6) 0.025 2015-02-01: 66.00% (12) 88.50% (12) 58.50% ( 8) 0.248 2015-03-01: 79.00% (15) 95.50% (12) 77.00% ( 9) 0.360 2015-04-01: 87.00% (15) 95.50% (12) 68.00% ( 9) 0.039 2015-05-01: 85.50% (18) 90.00% (12) 87.00% ( 9) 0.479 """ def get_time(r): r = r.strip() return date(year=int(r[0:4]), month=int(r[5:7]), day=int(r[8:10])) def get_field(r, field_name): m = re.match(r"(?P[^:]+): +" r"(?P[0-9.]+)% +" r"\( *(?P[0-9]+)\) +" r"(?P[0-9.]+)% +" r"\( *(?P[0-9]+)\) +" r"(?P[0-9.]+)% +" r"\( *(?P[0-9]+)\) +" r"(?P[0-9.]+)", r.strip()) return m.group(field_name) x = [get_time(r) for r in dwcd.split("\n") if r] y_a = [float(get_field(r, "value_a")) for r in dwcd.split("\n") if r] y_b = [float(get_field(r, "value_b")) for r in dwcd.split("\n") if r] y_c = [float(get_field(r, "value_c")) for r in dwcd.split("\n") if r] plt.plot(x, y_a, color="red", label="Group A") plt.plot(x, y_b, color="green", label="Group B") plt.plot(x, y_c, color="blue", label="Group C") plt.plot(date(2015,5,20), 101, marker="x", color="white") plt.ylabel("Y label") plt.legend(loc="upper left") fig = plt.gcf() fig.autofmt_xdate() plt.show() -- To email me, substitute nowhere->runbox, invalid->com. -- https://mail.python.org/mailman/listinfo/python-list
Re: Bug or intended behavior?
On Tue, 6 Jun 2017 13:16:00 -0400, Terry Reedy <tjre...@udel.edu> wrote: > On 6/5/2017 1:01 PM, Peter Pearson wrote: >> On Fri, 2 Jun 2017 10:17:05 -0700 (PDT), sean.diza...@gmail.com wrote: >> [snip] >>>>>> print "foo %s" % 1-2 >>> Traceback (most recent call last): >>>File "", line 1, in >>> TypeError: unsupported operand type(s) for -: 'str' and 'int' >> >> Others have already pointed out that you're assuming the >> wrong precedence: >> >> Say >> "foo %s" % (1-2) >> not >> ("foo %s" % 1) - 2 >> . >> >> Personally I prefer a less compact but more explicit alternative: >> >> "foo {}".format(1-2) > > More compact: > >>> f'foo {1-2}' > 'foo -1' Sarcastic thanks, dude. Excuse me while I scrub my screen with Clorox. Or maybe my eyeballs. More seriously, I thought "format" was the Cool New Thing toward which all the cool kids were moving. But here I tried to be cool and put in a plug for "format", and the hip community seems to be sticking up for "%". Can I never get with the times? -- To email me, substitute nowhere->runbox, invalid->com. -- https://mail.python.org/mailman/listinfo/python-list
Re: Bug or intended behavior?
On Tue, 6 Jun 2017 03:10:05 +1000, Chris Angelico wrote: > On Tue, Jun 6, 2017 at 3:01 AM, Peter Pearson wrote: [snip] >> Say >> "foo %s" % (1-2) >> not >> ("foo %s" % 1) - 2 >> . >> >> Personally I prefer a less compact but more explicit alternative: >> >> "foo {}".format(1-2) > > The trouble with the zen of Python is that people now use the word > "explicit" to mean "code that I like". What is more explicit here? It > uses a method call instead of an operator, but either way, it's > completely explicit that you want to populate the placeholders in a > template string. I meant simply that when you call "format", you don't have to think about the precedence of the "%" operator. Maybe "explicit" isn't the right word; I just make fewer mistakes when I stick with things that I use all the time (function calls, in this case). -- To email me, substitute nowhere->runbox, invalid->com. -- https://mail.python.org/mailman/listinfo/python-list
Re: How to change variable from list to float
On Mon, 5 Jun 2017 11:13:54 +0100, Paul Barry wrote: > On 3 June 2017 at 15:42, Gary Barkerwrote: > >> I have searched for a solution to this but have not found a suitable >> example. >> >> The attached code generates this error: Traceback (most recent call last): >> File "calcsignal.py", line 7, in >> siglevfromexist = 34.8 + existattn >> TypeError: unsupported operand type(s) for +: 'float' and 'list' >> >> How do I convert the list variable (i.e. existattn) to a float? >> >> Operating details are: >> Python 3.4.2 >> Debian 3.16.39-1+deb8u2 (2017-03-07) x86_64 GNU/Linux >> >> The following lines are the code in calcsignal.py: >> azdegpattrev = -47.40715077970316 >> azattndic = {-0.9: [-0.55], -0.5: [-0.46], 3.5: [-21.0], 1.4: [-7.48], >> 5.5: [-25.0], 0.0: [0.0], 1.9: [-21.0], 13.0: [-38.0], 15.0: [-39.0], 3.6: >> [-25.0], 20.0: [-39.0], -1.4: [-7.48], 90.0: [-65.0], -0.4: [-0.39], 0.5: >> [-0.46], 0.1: [-0.04], 1.0: [-1.31], -90.0: [-65.0], 40.0: [-42.0], 180.0: >> [-65.0], 1.5: [-10.0], -1.2: [-3.69], 0.3: [-0.28], -0.3: [-0.28], 0.2: >> [-0.15], -0.1: [-0.04], 1.1: [-2.34], -180.0: [-65.0], -0.2: [-0.15], 1.2: >> [-3.69], -40.0: [-42.0], 0.4: [-0.39], -5.5: [-25.0], -1.5: [-10.0], -20.0: >> [-39.0], 0.9: [-0.55], -3.5: [-21.0], -1.9: [-21.0], -15.0: [-39.0], -13.0: >> [-38.0], 1.3: [-5.39], -1.3: [-5.39], -3.6: [-25.0], -1.0: [-1.31], -1.1: >> [-2.34]} >> azlist = [-0.9, -0.5, 3.5, 1.4, 5.5, 0.0, 1.9, 13.0, 15.0, 3.6, 20.0, >> -1.4, 90.0, -0.4, 0.5, 0.1, 1.0, -90.0, 40.0, 180.0, 1.5, -1.2, 0.3, -0.3, >> 0.2, -0.1, 1.1, -180.0, -0.2, 1.2, -40.0, 0.4, -5.5, -1.5, -20.0, 0.9, >> -3.5, -1.9, -15.0, -13.0, 1.3, -1.3, -3.6, -1.0, -1.1] >> azlist = [float(i) for i in azlist] >> closestaz = min(azlist, key=lambda x: abs(x - azdegpattrev)) >> existattn = azattndic[closestaz] >> siglevfromexist = 34.8 + existattn > > The value in existattn is a single element list. The single element is a > float, so just refer to it in your calculation, like so: > > siglevfromexist = 34.8 + existattn[0] But as you do so, remember to wonder why the author of this code made the elements of azattndic *lists* of values instead of simple single values. Then, worry that someday your corrected code, which uses only the first value of the list, will be handed a list with several values. (True, it will execute without exception; but right now, today, you know that if the list length is not 1, you're confused.) -- To email me, substitute nowhere->runbox, invalid->com. -- https://mail.python.org/mailman/listinfo/python-list
Re: Bug or intended behavior?
On Fri, 2 Jun 2017 10:17:05 -0700 (PDT), sean.diza...@gmail.com wrote: [snip] print "foo %s" % 1-2 > Traceback (most recent call last): > File "", line 1, in > TypeError: unsupported operand type(s) for -: 'str' and 'int' Others have already pointed out that you're assuming the wrong precedence: Say "foo %s" % (1-2) not ("foo %s" % 1) - 2 . Personally I prefer a less compact but more explicit alternative: "foo {}".format(1-2) -- To email me, substitute nowhere->runbox, invalid->com. -- https://mail.python.org/mailman/listinfo/python-list
Re: Nested Loop to Generate Triangle
On Thu, 25 May 2017 09:28:31 -0700 (PDT), Victor Demelo wrote: > I need the triangle to be in reverse. The assignment requires a nested > loop to generate a triangle with the user input of how many lines. > > Currently, I get answers such as: > > OOO > OO > O > > When I actually need it to be like this: > > OOO > OO >O > > I just need to get it flipped-over on the other side. > > Here is the code I have written, thank you. > > base_size = int(input("How many lines? ")) > columns = base_size > > for row in range (base_size) : >for columns in range (columns) : >print('O', end='') >print() Seems like you're close to a solution. You just need to print a certain number of spaces at the beginning of each line, right? Warning: When you say for columns in range (columns) : you're creating a confusing situation with the name "columns": the original meaning, an integer equal to base_size, is now "shadowed" by a new meaning. This sort of thing tends to create trouble. Besides, you probably meant to say range(base_size), not range(columns). I don't know how much you're supposed to know about Python basics, but have you encountered expressions like 5*"Hello" yet? -- To email me, substitute nowhere->runbox, invalid->com. -- https://mail.python.org/mailman/listinfo/python-list
Re: Promiscuous ports under Linux
On Thu, 4 May 2017 18:04:02 + (UTC), Grant Edwards wrote: > On 2017-05-04, Peter Pearson <pkpearson@nowhere.invalid> wrote: > >> I'm curious to survey all my LAN traffic in various ways, and it seems >> likely that I will see phenomena that I don't understand, and focussing >> in on those phenomena is likely to require more flexible filtering >> than Wireshark can provide. I expect to leave this process running for >> maybe 24 hours at a stretch, maybe longer, with real-time alerts when >> interesting things occur. > > You can libpcap (which is what wireshark uses on Linux) to deal with > the details of capturing the packets and do the analysis in Python. > >> Maybe Wireshark can do everything I'll ever need to do, but it seems >> so complicated, and Python seems so simple . . . > > I've been using pylibpcap for yonks, and have no complaints. > > https://sourceforge.net/projects/pylibpcap/ [snip] Hey, that might do the job. Thanks! -- To email me, substitute nowhere->runbox, invalid->com. -- https://mail.python.org/mailman/listinfo/python-list
Re: Promiscuous ports under Linux
On Thu, 04 May 2017 10:26:45 GMT, alister <alister.w...@ntlworld.com> wrote: > On Wed, 03 May 2017 23:57:49 +0000, Peter Pearson wrote: > >> Cobbling together a minimalist ethernet-sniffing program, I was hoping >> to use this simple mechanism for setting the socket to "promiscuous >> mode" (to see all traffic going past, instead of just traffic addressed >> to my machine): >> >> s.ioctl(socket.SIO_RCVALL, socket.RCVALL_ON) >> >> Unfortunately, it seems that that mechanism is available under Windows >> but not under Linux. Googling around for Linux equivalents, I found >> only very contorted solutions, and concluded that maybe this lacuna >> persists because Linux users find it convenient to invoke promiscuous >> mode from the command line, instead: >> >> $ sudo ip link set eth0 promisc on $ netstat -i# (Verify >> that the P flag is set.) >> >> This somehow fails: my sniffer continues to see only broadcasts, >> but if I run dumpcap at the same time, dumpcap captures lots of traffic. >> >> So my question is now two questions: >> >> . Is it true that going permiscuous under Linux must be somewhat ugly? >>(It's OK if it is, I'll just copy the ugly code and get moving >>again.) >> >> . Why doesn't the command-line "promisc on" work? (Granted, this is >>maybe a Linux question.) >> >> Thanks. > > any particular reason why you wish to re-invent this particular wheel > when wireshark is freely available (& the de-facto tool of choice for > most network engineers) I'm curious to survey all my LAN traffic in various ways, and it seems likely that I will see phenomena that I don't understand, and focussing in on those phenomena is likely to require more flexible filtering than Wireshark can provide. I expect to leave this process running for maybe 24 hours at a stretch, maybe longer, with real-time alerts when interesting things occur. Maybe Wireshark can do everything I'll ever need to do, but it seems so complicated, and Python seems so simple . . . -- To email me, substitute nowhere->runbox, invalid->com. -- https://mail.python.org/mailman/listinfo/python-list
Re: Promiscuous ports under Linux
On Wed, 3 May 2017 18:09:08 -0700, Rob Gaddi wrote: > On 05/03/2017 04:57 PM, Peter Pearson wrote: >> Cobbling together a minimalist ethernet-sniffing program, I was hoping >> to use this simple mechanism for setting the socket to "promiscuous >> mode" (to see all traffic going past, instead of just traffic addressed >> to my machine): >> >> s.ioctl(socket.SIO_RCVALL, socket.RCVALL_ON) >> >> Unfortunately, it seems that that mechanism is available under Windows >> but not under Linux. Googling around for Linux equivalents, I found >> only very contorted solutions, and concluded that maybe this lacuna >> persists because Linux users find it convenient to invoke promiscuous >> mode from the command line, instead: >> >> $ sudo ip link set eth0 promisc on >> $ netstat -i# (Verify that the P flag is set.) >> >> This somehow fails: my sniffer continues to see only broadcasts, >> but if I run dumpcap at the same time, dumpcap captures lots of traffic. >> >> So my question is now two questions: >> >> . Is it true that going permiscuous under Linux must be somewhat ugly? >>(It's OK if it is, I'll just copy the ugly code and get moving again.) >> >> . Why doesn't the command-line "promisc on" work? (Granted, this is >>maybe a Linux question.) >> >> Thanks. >> > > Tried running it as root? Good question; I should have mentioned: Yes: $ sudo python3 sniff_survey.py -- To email me, substitute nowhere->runbox, invalid->com. -- https://mail.python.org/mailman/listinfo/python-list