h5py.File() gives error message
Dear list, The following Python code gives an error message # Python code starts here: import numpy as np import h5py train_dataset = h5py.File('datasets/train_catvnoncat.h5', "r") # Python code ends The error message: train_dataset = h5py.File('train_catvnoncat.h5', "r") Traceback (most recent call last): File "", line 1, in File "/Users/M/anaconda/lib/python3.6/site-packages/h5py/_hl/files.py", line 269, in __init__ fid = make_fid(name, mode, userblock_size, fapl, swmr=swmr) File "/Users/M/anaconda/lib/python3.6/site-packages/h5py/_hl/files.py", line 99, in make_fid fid = h5f.open(name, flags, fapl=fapl) File "h5py/_objects.pyx", line 54, in h5py._objects.with_phil.wrapper File "h5py/_objects.pyx", line 55, in h5py._objects.with_phil.wrapper File "h5py/h5f.pyx", line 78, in h5py.h5f.open OSError: Unable to open file (unable to open file: name = 'train_catvnoncat.h5', errno = 2, error message = 'No such file or directory', flags = 0, o_flags = 0) My directory is correct, and the dataset folder with file is there. Why error message? Is it h5py.File() or is it my file? Everything seems pretty simple, what's going on? Thank you! -- https://mail.python.org/mailman/listinfo/python-list
Re: h5py.File() gives error message
Oh, I was running a debug file, that's why the path is different. The file is here, https://www.dropbox.com/s/6jx4rzyg9xwl95m/train_catvnoncat.h5?dl=0 Is anyone able to get it working? Thank you! On Tue, Oct 24, 2017 at 10:37 PM, Dennis Lee Bieber wrote: > On Tue, 24 Oct 2017 18:02:26 -0700, Rob Gaddi > declaimed the following: > > Whoops, I may have gotten the wrong level of quoting -- my > apologies if > so (I did have agent fetch the original posting, but might not have had > that active when I hit "reply") > -- > Wulfraed Dennis Lee Bieber AF6VN > wlfr...@ix.netcom.comHTTP://wlfraed.home.netcom.com/ > > -- > https://mail.python.org/mailman/listinfo/python-list > -- https://mail.python.org/mailman/listinfo/python-list
Re: h5py.File() gives error message
wow, thanks so much! I don't know how you figured that it's HTML, but that's awesome! Mike On Wed, Oct 25, 2017 at 5:20 AM, Peter Otten <__pete...@web.de> wrote: > C W wrote: > > > Oh, I was running a debug file, that's why the path is different. > > > > The file is here, > > https://www.dropbox.com/s/6jx4rzyg9xwl95m/train_catvnoncat.h5?dl=0 > > > > Is anyone able to get it working? Thank you! > > Hm, that file seems to contain HTML and that causes an OSError here, too: > > $ head -n3 datasets/train_catvnoncat.h5 > > > > > $ python3 > Python 3.4.3 (default, Nov 17 2016, 01:08:31) > [GCC 4.8.4] on linux > Type "help", "copyright", "credits" or "license" for more information. > >>> import h5py > >>> train_dataset = h5py.File('datasets/train_catvnoncat.h5', "r") > Traceback (most recent call last): > File "", line 1, in > File "/usr/lib/python3/dist-packages/h5py/_hl/files.py", line 207, in > __init__ > fid = make_fid(name, mode, userblock_size, fapl) > File "/usr/lib/python3/dist-packages/h5py/_hl/files.py", line 79, in > make_fid > fid = h5f.open(name, h5f.ACC_RDONLY, fapl=fapl) > File "h5f.pyx", line 71, in h5py.h5f.open (h5py/h5f.c:1806) > OSError: unable to open file (File accessibilty: Unable to open file) > > It's not exactly what you see, but that may be due to differing software > versions. > When I replace the HTML file with its namesake found at > > https://github.com/lalxyy/NEU-MCM-Training-4/blob/master/cod > e/datasets/train_catvnoncat.h5 > > I can open it: > > $ file datasets/train_catvnoncat.h5 > datasets/train_catvnoncat.h5: Hierarchical Data Format (version 5) data > > $ python3 > Python 3.4.3 (default, Nov 17 2016, 01:08:31) > [GCC 4.8.4] on linux > Type "help", "copyright", "credits" or "license" for more information. > >>> import h5py > >>> train_dataset = h5py.File('datasets/train_catvnoncat.h5', "r") > >>> > > -- > https://mail.python.org/mailman/listinfo/python-list > -- https://mail.python.org/mailman/listinfo/python-list
I have anaconda, but Pycharm can't find it
Hello all, I am a first time PyCharm user. I have Python 3 and Anaconda installed. They work together on Sublime Text, but not on Pycharm. Pycharm tells me it cannot find modules numpy, matplotlib, etc. What should I do? I tried to set the interpreter environment, and a few other options, none seem to work. This is the typical solution, but it does not work https://stackoverflow.com/questions/35623776/import-numpy-on-pycharm Thanks, -Mike -- https://mail.python.org/mailman/listinfo/python-list
Why does Jupyter Notebook searches files in folders, but PyCharm and Sublime Text does not?
Hi all, I am confused why Jupyter Notebook searches files in subfolder, but PyCharm and Sublime Text 3 does not. Is there a rule? For example, I have a module or file called lr_utils.py in the current folder. If I run the following line in Jupyter, it's fine. > import lr_utils But in PyCharm, I get the error, ModuleNotFoundError: No module named 'lr_utils' If I run it in Sublime Text, it's find too > import os > os.chdir("Users/My_name/Desktop/Python_Codes") > import lr_utils Why the code works in one but not the other? Thank you! -- https://mail.python.org/mailman/listinfo/python-list
How do you debug in Python? Coming from a Matlab and R user. I'm already aware of pdb.
Hello everyone, I'm a long time Matlab and R user working on data science. How do you troubleshooting/debugging in Python? I ran into this impossible situation to debug: class person: def __init__(self, id, created_at, name, attend_date, distance): """Create a new `person`. """ self._id = id self.created_at = created_at self.name = name self.attend_date = attend_date self.distance = distance @classmethod def get_person(self, employee): """Find and return a person by. """ return person(employee['created_at'], employee['id'], employee['name'], employee['attend_date'], employee['distance'] ) I got an error message saying id was 'str', but expecting 'int'. In R, I use the interactive IDE with console. Wherever the error interrupts the code, I just evaluate that line in the console. Very convenient! If this error was in R, I would have tried: > self._id = 123 But, I can't do that here! What do I do? Do I HAVE TO instantiate an object first? It's not convenient if I have 10 of these objects around. I need to instantiate 10 objects. I know hardcore computer scientists would tell me about Python debugger. R also has one, but nobody ever uses it. I don't find them user-friendly! Thanks a lot, Mike -- https://mail.python.org/mailman/listinfo/python-list
Re: How do you debug in Python? Coming from a Matlab and R user. I'm already aware of pdb.
Thanks for your replies. My apologies for the poor indent. I'm rewriting the code below. class NEODatabase: def __init__(self, id, created_at, name, attend_date, distance): self._id = id self.created_at = created_at self.name = name self.attend_date = attend_date self.distance = distance @classmethod def get_person(self, employee): return PERSONDatabase(employee['created_at'], employee['id'], employee['name'], employee['attend_date'], employee['distance']) I have a naive question. How do I use traceback or trace the stack? In particular, I'm using VS Code with Python interactive console. Say, I want to print the value of employee['name']. Can I do it? My understanding is that these classes are just "skeletons". I must create an instance, assign values, then test? Thanks so much, Mike On Tue, Jan 26, 2021 at 9:55 PM Ed Leafe wrote: > On Jan 26, 2021, at 18:16, Grant Edwards > wrote: > > > >> How do you troubleshooting/debugging in Python? > > > > Mostly I read exception trace and read the code and think about it. > > > > If that doesn't work, I add some print() or syslog() calls. > > > > If I really get stuck, I try to write as small a program as possible > > that demonstrates the problem. > > I do the first two, but if I get really stuck, I use the pudb debugger ( > https://pypi.org/project/pudb/). > > Using that, I can see all the locals, jump to any point in the stack and > see the locals there, or shell into ipython if I need to run some quick > code. For me, this is much faster than trying to write an additional > program that is close enough to the problem code to be useful. > > -- Ed Leafe > > > > > > > -- > https://mail.python.org/mailman/listinfo/python-list > -- https://mail.python.org/mailman/listinfo/python-list
Re: How do you debug in Python? Coming from a Matlab and R user. I'm already aware of pdb.
Hi Michael, Here's the code again, class should be called PERSONDatabase, misspelled earlier: class PERSONDatabase: def __init__(self, id, created_at, name, attend_date, distance): self._id = id self.created_at = created_at self.name= name self.attend_date = attend_date self.distance = distance @classmethod def get_person(self, employee): return PERSONDatabase(employee['created_at'], employee['id'], employee['name'], employee['attend_date'], employee['distance']) The PERSONDatabase class is called from main. This is the trace back I got from the VS code: Traceback (most recent call last): File "/Users/Mike/Documents/Mike/main.py", line 95, in main() File "/Users/Mike/Documents/Mike/main.py", line 86, in main args = get_feed() File "/Users/Mike/DocumentsMike/main.py", line 32, in get_feed result = [PERSONatabase.get_person(raw_person) for raw_neo in raw_objects] File "/Users/Mike/Documents/Mike/main.py", line 32, in result = [NEODatabase.get_person(raw_person) for raw_neo in raw_objects] File "/Users/Mike/Documents/Mike/database.py", line 24, in get_person return PERSONDatabase(person['created_at'], KeyError: 'created_at' Thank you very much! On Wed, Jan 27, 2021 at 12:10 AM Michael Torrie wrote: > On 1/26/21 8:37 PM, C W wrote: > > I have a naive question. How do I use traceback or trace the stack? In > > particular, I'm using VS Code with Python interactive console. > > Show us the traceback here and we can help you interpret it. Copy and > paste it from the VS Code console. > > > Say, I want to print the value of employee['name']. Can I do it? > > Yes I would think so. > > > My understanding is that these classes are just "skeletons". I must > > create an instance, assign values, then test? > > Can't you just do something like this? > > class NEODatabase: > def __init__(self, id, created_at, name, attend_date, distance): > self._id = id > self.created_at = created_at > self.name = name > self.attend_date = attend_date > self.distance = distance > > @classmethod > def get_person(self, employee): > print (employee['name']) > > return PERSONDatabase(employee['created_at'], > employee['id'], > employee['name'], > employee['attend_date'], > employee['distance']) > > -- > https://mail.python.org/mailman/listinfo/python-list > -- https://mail.python.org/mailman/listinfo/python-list
Re: How do you debug in Python? Coming from a Matlab and R user. I'm already aware of pdb.
Hi Cameron, Yes, you are correct in all above. There's a mistake in my copy paste. Thanks for pointing that out! On Wed, Jan 27, 2021 at 12:58 AM Cameron Simpson wrote: > On 27Jan2021 00:19, C W wrote: > >Here's the code again, class should be called PERSONDatabase, > >misspelled > >earlier: > >class PERSONDatabase: > > def __init__(self, id, created_at, name, attend_date, distance): > > self._id = id > > self.created_at = created_at > > self.name= name > > self.attend_date = attend_date > > self.distance = distance > > Here's you're setting attributes (which is a very normal thing to do). > > > @classmethod > > def get_person(self, employee): > > return PERSONDatabase(employee['created_at'], > >employee['id'], > >employee['name'], > >employee['attend_date'], > >employee['distance']) > > I think this "employee" is called "person" in the code the traceback > came from. It is better when these two things match. > > >The PERSONDatabase class is called from main. This is the trace back I got > >from the VS code: > > > >Traceback (most recent call last): > > File "/Users/Mike/Documents/Mike/main.py", line 95, in > > main() > > File "/Users/Mike/Documents/Mike/main.py", line 86, in main > > args = get_feed() > > File "/Users/Mike/DocumentsMike/main.py", line 32, in get_feed > > result = [PERSONatabase.get_person(raw_person) for raw_neo in > >raw_objects] > > File "/Users/Mike/Documents/Mike/main.py", line 32, in > > result = [NEODatabase.get_person(raw_person) for raw_neo in > >raw_objects] > > File "/Users/Mike/Documents/Mike/database.py", line 24, in get_person > > return PERSONDatabase(person['created_at'], > >KeyError: 'created_at' > > Here's you're trying to index another object using a string, which seems > to resemble the .created_at attribute in your PERSONDatabase object. > > I would presume from this that the "person" object at the bottom of the > traceback is the "raw_person" called above it. But I do not see > raw_person defined anywhere. Are you sure you didn't mean to pass > "raw_neo" instead of "raw_person"? That would be more normal, since > you're iterating over "raw_objects". > > Cheers, > Cameron Simpson > -- > https://mail.python.org/mailman/listinfo/python-list > -- https://mail.python.org/mailman/listinfo/python-list
Re: How do you debug in Python? Coming from a Matlab and R user. I'm already aware of pdb.
For learning purposes, here's the files: https://www.dropbox.com/sh/a3iy40rcvib4uvj/AAADmlM2i6NquWC1SV0nZfnDa?dl=0 Yes, you are correct about "employee" and "person" discrepancies. For now, the list comprehension is where I get stuck. I'd like to know how the experts on here are approaching and debugging this. Bonus if no debugger or breakpoint. Just the good ol' run the function and evaluate/print output for problems. Thanks so much, Mike On Wed, Jan 27, 2021 at 10:53 AM Michael Torrie wrote: > On 1/26/21 10:19 PM, C W wrote: > > Traceback (most recent call last): > >File "/Users/Mike/Documents/Mike/main.py", line 95, in > > main() > >File "/Users/Mike/Documents/Mike/main.py", line 86, in main > > args = get_feed() > >File "/Users/Mike/DocumentsMike/main.py", line 32, in get_feed > > result = [PERSONatabase.get_person(raw_person) for raw_neo in > > raw_objects] > >File "/Users/Mike/Documents/Mike/main.py", line 32, in > > result = [NEODatabase.get_person(raw_person) for raw_neo in > > raw_objects] > >File "/Users/Mike/Documents/Mike/database.py", line 24, in get_person > > return PERSONDatabase(person['created_at'], > > KeyError: 'created_at' > > The actual error is the last part, which is a KeyError on line 24. A > key error usually is from a dictionary-like object and it means the > requested key is not found in that object. In other words, this person > object has no "created_at" key. Hope that makes sense. > > I do not know why the code you posted refers to "employee" but the > traceback refers to "person." > > In any case the trace back shows you what called what until the error > occurred. You can trace the execution of the code simply by following > it. main() called get_feed() which set up a list comprehension, which > calls get_person() which is where the error is occurring. I'm not > following the list comprehension stuff; I don't know why python is first > referring to PERSONatabase and then refers to NEODatabase. > -- > https://mail.python.org/mailman/listinfo/python-list > -- https://mail.python.org/mailman/listinfo/python-list
Re: IDE tools to debug in Python?
I'm not expert in Python, but I sure tried many IDEs to kick off Python programming. I started with PyCharm, but I had a problem with it constantly scanning the background, even after I turned that feature off. My favorite (I'm using now) is VS Code with Python extension, it's very light. Recently also started background scanning, but that's generally done in 30 seconds. On Wed, Jan 27, 2021 at 1:51 PM Michał Jaworski wrote: > PyCharm has all these debugging capabilities and there is a community > edition that you can use for free. If you earn for the living with Python > it is worth investing in professional edition though. > > Michał Jaworski > > > Wiadomość napisana przez flaskee via Python-list > w dniu 27.01.2021, o godz. 19:32: > > > > > > While print() is groovy and all, > > if anyone runs across a non-pdb python debugger (standalone or IDE-based) > > please let me know. > > > > I too was blessed with IDE-based debugging (in the 90's!) > > * where you can set break point(s); > > * have the program stop right before a suspected failure point; > > * check the contents of ALL variables, and choose whether to restart; > > * or skip a few lines before restarting; > > * or change a variable (hot, move back a few lines and restart, etc. > > * Some, would even let you alter the code a bit before restarting. > > > > I too, miss this. > > > > > > Hopefully I did not miss someone mentioning > > such a python tool in the prior thread. > > > > Thanks! > > > > -- > > https://mail.python.org/mailman/listinfo/python-list > -- https://mail.python.org/mailman/listinfo/python-list
Re: IDE tools to debug in Python?
I don't know exactly, but it shows as inspection on the bottom left corner. I believe it's indexing in the background. On Wed, Jan 27, 2021 at 3:25 PM Grant Edwards wrote: > On 2021-01-27, C W wrote: > > I'm not expert in Python, but I sure tried many IDEs to kick off Python > > programming. > > > > I started with PyCharm, but I had a problem with it constantly scanning > the > > background, even after I turned that feature off. > > What is it scanning? > > > My favorite (I'm using now) is VS Code with Python extension, it's very > > light. Recently also started background scanning, but that's generally > done > > in 30 seconds. > > Same question, what is it scanning? > > -- > Grant > > -- > https://mail.python.org/mailman/listinfo/python-list > -- https://mail.python.org/mailman/listinfo/python-list
Re: IDE tools to debug in Python?
I meant bottom right corner, not left. opps! On Wed, Jan 27, 2021 at 3:36 PM C W wrote: > I don't know exactly, but it shows as inspection on the bottom left corner. > > I believe it's indexing in the background. > > On Wed, Jan 27, 2021 at 3:25 PM Grant Edwards > wrote: > >> On 2021-01-27, C W wrote: >> > I'm not expert in Python, but I sure tried many IDEs to kick off Python >> > programming. >> > >> > I started with PyCharm, but I had a problem with it constantly scanning >> the >> > background, even after I turned that feature off. >> >> What is it scanning? >> >> > My favorite (I'm using now) is VS Code with Python extension, it's very >> > light. Recently also started background scanning, but that's generally >> done >> > in 30 seconds. >> >> Same question, what is it scanning? >> >> -- >> Grant >> >> -- >> https://mail.python.org/mailman/listinfo/python-list >> > -- https://mail.python.org/mailman/listinfo/python-list
Re: How do you debug in Python? Coming from a Matlab and R user. I'm already aware of pdb.
Great tutorial Irv, very simple with if-else example, gets the point across. My main takeaway from the discussion so far is that: you can't troubleshoot Python without some kind of breakpoint or debugger. I suppose I can't take the functional programming debugger style like C, Matlab, or R, and apply it to a OOP language like Python. On Wed, Jan 27, 2021 at 5:26 PM Irv Kalb wrote: > On Jan 26, 2021, at 5:28 PM, William Ray Wing via Python-list < > python-list@python.org> wrote: > > > > > > > >> On Jan 26, 2021, at 2:00 PM, C W wrote: > >> > >> Hello everyone, > >> > >> I'm a long time Matlab and R user working on data science. How do you > >> troubleshooting/debugging in Python? > >> > > > > Another approach is to run the code in an IDE. I happen to use Wing, > but that is a coincidence. But almost ANY IDE will let you set a break > point, then single-step through your code starting at the break point and > examine the values of your variables at each step. Sometimes this is an > awfully big hammer for what is a head-slapping mistake. But it has never > failed me. > > > > > > I'm happy with the PyCharm IDE. I created a video showing how to use the > debugger in that environment. It's available on YouTube here: > > https://www.youtube.com/watch?v=cxAOSQQwDJ4 <mailto:python-list@python.org > > > > Irv > > -- > https://mail.python.org/mailman/listinfo/python-list > -- https://mail.python.org/mailman/listinfo/python-list
Is there a way to subtract 3 from every digit of a number?
Hello everyone, I'm curious if there is a way take number and back each digit by 3 ? 2342 becomes 9019 8475 becomes 5142 5873 becomes 2540 The tricky part is that 2 becomes 9, not -1. Here's my toy example and what I attempted, > test_series = pd.Series(list(['2342', '8475', '5873'])) > test_series 02342 18475 25873 dtype: object > test_series.str.split('') [, 2, 3, 4, 2, ] [, 8, 4, 7, 5, ] [, 5, 8, 7, 3, ] dtype: object What a good approach to this? Is there a method or function that should be handling this? Thanks so much! Mike -- https://mail.python.org/mailman/listinfo/python-list
Re: Is there a way to subtract 3 from every digit of a number?
Thanks so much everyone, I appreciate it! Ming, your solution is awesome. More importantly, very clear explanations on how and why. So, I appreciate that. Thanks again, cheers! Mike On Sun, Feb 21, 2021 at 12:08 AM <2qdxy4rzwzuui...@potatochowder.com> wrote: > On 2021-02-20 at 20:49:15 -0800, > Dan Stromberg wrote: > > > On Sat, Feb 20, 2021 at 7:13 PM Ming wrote: > > > > > I just wrote a very short code can fulfill your needs: > > > > > > a = 2342 > > > b = int("".join(map(lambda x: str((int(x)-3)%10) ,list(str(a) > > > > > I tend to favor plenty of temporary variables with descriptive names, but > > this is indeed short. > > > > Apart from that, you may find that using a generator expression is > shorter > > and clearer than map+lambda. It should allow to additionally eliminate > the > > list conversion. > > > > So in the terse form you've got there, it'd be more like: > > b = int(''.join(str((int(x) - 3) % 10) for x in str(a)) > > > > But in real life, I'd try to use descriptive variable names for some of > the > > subexpressions in that. This makes reading and debugging simpler, which > is > > important because the maintenance phase of software is almost always much > > longer and costly than the development phase. And although you could do > a > > generator expression for each of the different parts of (int(x) - 3) % > 10, > > I kinda like having a named function for just that piece. > > > > So maybe: > > def rot_3(character): > > """Convert to int, subtract 3 and mod 10.""" > > digit = int(character) > > assert 0 <= digit <= 9 > > return (digit - 3) % 10 > > > > > > def descriptive_minus_three_caesar(input_number): > > """Convert to a -3 caesar cypher on an integer.""" > > string_number = str(input_number) > > rotated_digits = (rot_3(character) for character in string_number) > > output_string = ''.join(str(digit) for digit in rotated_digits) > > output_number = int(output_string) > > return output_number > > >>> descriptive_minus_three_caesar('38') > 5 > > The problem is underspecified, and the examples are lacking, but based > on the phrase "each digit" and the examples that contain a 3, I'd prefer > to see "38" become "05." > -- > https://mail.python.org/mailman/listinfo/python-list > -- https://mail.python.org/mailman/listinfo/python-list
Re: Is there a way to subtract 3 from every digit of a number?
I do want to follow up, if I may. In Ming's example, a = 2342 b = int("".join(map(lambda x: str((int(x)-3)%10) ,list(str(a) What's the best approach to apply to a dataframe column, rather than just one value? Here's my attempt using df[col_1''].apply(), df['col_1'].apply(lambda:a int("".join(map(lambda x: str((int(x)-3)%10) ,list(str(a)) Thanks! On Sun, Feb 21, 2021 at 9:12 AM C W wrote: > Thanks so much everyone, I appreciate it! > > Ming, your solution is awesome. More importantly, very clear explanations > on how and why. So, I appreciate that. > > Thanks again, cheers! > > Mike > > On Sun, Feb 21, 2021 at 12:08 AM <2qdxy4rzwzuui...@potatochowder.com> > wrote: > >> On 2021-02-20 at 20:49:15 -0800, >> Dan Stromberg wrote: >> >> > On Sat, Feb 20, 2021 at 7:13 PM Ming wrote: >> > >> > > I just wrote a very short code can fulfill your needs: >> > > >> > > a = 2342 >> > > b = int("".join(map(lambda x: str((int(x)-3)%10) ,list(str(a) >> > > >> > I tend to favor plenty of temporary variables with descriptive names, >> but >> > this is indeed short. >> > >> > Apart from that, you may find that using a generator expression is >> shorter >> > and clearer than map+lambda. It should allow to additionally eliminate >> the >> > list conversion. >> > >> > So in the terse form you've got there, it'd be more like: >> > b = int(''.join(str((int(x) - 3) % 10) for x in str(a)) >> > >> > But in real life, I'd try to use descriptive variable names for some of >> the >> > subexpressions in that. This makes reading and debugging simpler, >> which is >> > important because the maintenance phase of software is almost always >> much >> > longer and costly than the development phase. And although you could >> do a >> > generator expression for each of the different parts of (int(x) - 3) % >> 10, >> > I kinda like having a named function for just that piece. >> > >> > So maybe: >> > def rot_3(character): >> > """Convert to int, subtract 3 and mod 10.""" >> > digit = int(character) >> > assert 0 <= digit <= 9 >> > return (digit - 3) % 10 >> > >> > >> > def descriptive_minus_three_caesar(input_number): >> > """Convert to a -3 caesar cypher on an integer.""" >> > string_number = str(input_number) >> > rotated_digits = (rot_3(character) for character in string_number) >> > output_string = ''.join(str(digit) for digit in rotated_digits) >> > output_number = int(output_string) >> > return output_number >> >> >>> descriptive_minus_three_caesar('38') >> 5 >> >> The problem is underspecified, and the examples are lacking, but based >> on the phrase "each digit" and the examples that contain a 3, I'd prefer >> to see "38" become "05." >> -- >> https://mail.python.org/mailman/listinfo/python-list >> > -- https://mail.python.org/mailman/listinfo/python-list
Re: Is there a way to subtract 3 from every digit of a number?
I got it to work! I defined a separate function, and put it into df['col_1'].apply(). Not the most elegant, but it worked. I'm also curious how people on this mailing list would do it. Cheers! On Sun, Feb 21, 2021 at 9:21 AM C W wrote: > I do want to follow up, if I may. In Ming's example, > > a = 2342 > b = int("".join(map(lambda x: str((int(x)-3)%10) ,list(str(a) > > What's the best approach to apply to a dataframe column, rather than just > one value? Here's my attempt using df[col_1''].apply(), > df['col_1'].apply(lambda:a int("".join(map(lambda x: str((int(x)-3)%10) > ,list(str(a)) > > Thanks! > > On Sun, Feb 21, 2021 at 9:12 AM C W wrote: > >> Thanks so much everyone, I appreciate it! >> >> Ming, your solution is awesome. More importantly, very clear explanations >> on how and why. So, I appreciate that. >> >> Thanks again, cheers! >> >> Mike >> >> On Sun, Feb 21, 2021 at 12:08 AM <2qdxy4rzwzuui...@potatochowder.com> >> wrote: >> >>> On 2021-02-20 at 20:49:15 -0800, >>> Dan Stromberg wrote: >>> >>> > On Sat, Feb 20, 2021 at 7:13 PM Ming wrote: >>> > >>> > > I just wrote a very short code can fulfill your needs: >>> > > >>> > > a = 2342 >>> > > b = int("".join(map(lambda x: str((int(x)-3)%10) ,list(str(a) >>> > > >>> > I tend to favor plenty of temporary variables with descriptive names, >>> but >>> > this is indeed short. >>> > >>> > Apart from that, you may find that using a generator expression is >>> shorter >>> > and clearer than map+lambda. It should allow to additionally >>> eliminate the >>> > list conversion. >>> > >>> > So in the terse form you've got there, it'd be more like: >>> > b = int(''.join(str((int(x) - 3) % 10) for x in str(a)) >>> > >>> > But in real life, I'd try to use descriptive variable names for some >>> of the >>> > subexpressions in that. This makes reading and debugging simpler, >>> which is >>> > important because the maintenance phase of software is almost always >>> much >>> > longer and costly than the development phase. And although you could >>> do a >>> > generator expression for each of the different parts of (int(x) - 3) % >>> 10, >>> > I kinda like having a named function for just that piece. >>> > >>> > So maybe: >>> > def rot_3(character): >>> > """Convert to int, subtract 3 and mod 10.""" >>> > digit = int(character) >>> > assert 0 <= digit <= 9 >>> > return (digit - 3) % 10 >>> > >>> > >>> > def descriptive_minus_three_caesar(input_number): >>> > """Convert to a -3 caesar cypher on an integer.""" >>> > string_number = str(input_number) >>> > rotated_digits = (rot_3(character) for character in >>> string_number) >>> > output_string = ''.join(str(digit) for digit in rotated_digits) >>> > output_number = int(output_string) >>> > return output_number >>> >>> >>> descriptive_minus_three_caesar('38') >>> 5 >>> >>> The problem is underspecified, and the examples are lacking, but based >>> on the phrase "each digit" and the examples that contain a 3, I'd prefer >>> to see "38" become "05." >>> -- >>> https://mail.python.org/mailman/listinfo/python-list >>> >> -- https://mail.python.org/mailman/listinfo/python-list
Re: Is there a way to subtract 3 from every digit of a number?
Hey Avi, I am a long time R user now using Python. So, this is my attempt to master the language. The problem for me is that I often have an idea about how things are done in R, but not sure to what functions are available in Python. I hope that clears up some confusion. Cheer! On Sun, Feb 21, 2021 at 9:44 AM Chris Angelico wrote: > On Mon, Feb 22, 2021 at 1:39 AM Avi Gross via Python-list > wrote: > > But you just moved the goalpost by talking about using a data.frame as > that > > (and I assume numpy and pandas) are not very basic Python. > > Given that the original post mentioned a pd.Series, I don't know how > far the goalposts actually moved :) > > ChrisA > -- > https://mail.python.org/mailman/listinfo/python-list > -- https://mail.python.org/mailman/listinfo/python-list
Which part of the loop is it going through in this class frame?
Hello, I am new to OOP. I'm a bit confused about the following code. class Clock(object): def __init__(self, time): self.time = time def print_time(self): time = '6:30' print(self.time) clock = Clock('5:30') clock.print_time() 5:30 I set time to 6:30, but it's coming out to 5:30. I guess it's because I passed in 5:30, so, it's replaced? How does line-by-line execution run inside a frame? How does __init__ work? I understand you must have __init__. Is it run before print_time(), if so, why don't I just set self.time = '6:30' instead of self.time = time? Thanks! -- https://mail.python.org/mailman/listinfo/python-list
Re: Which part of the loop is it going through in this class frame?
Thank you guys, lots of great answers, very helpful. I got it! A follow-up question: How did the value of "object" get passed to "time"? Obviously, they have different names. How did Python make that connection? Code is below for convenience. class Clock(object): def __init__(self, time): self.time = time def print_time(self): time = '6:30' print(self.time) clock = Clock('5:30') clock.print_time() 5:30 Thank you! On Thu, Mar 8, 2018 at 6:30 AM, Steven D'Aprano < steve+comp.lang.pyt...@pearwood.info> wrote: > On Wed, 07 Mar 2018 16:57:51 -0500, C W wrote: > > > Hello, > > > > I am new to OOP. I'm a bit confused about the following code. > > > > class Clock(object): > > def __init__(self, time): > > self.time = time > > Here you set the instance attribute "self.time". > > > def print_time(self): > > time = '6:30' > > print(self.time) > > Here you set the local variable "time", which is completely unrelated to > the attribute "self.time". > > If you are used to languages where "foo" inside a method is a short-cut > for "self.foo" or "this.foo", Python does not do that. Local variables > and instance attributes are distinct concepts, and Python keeps them > distinct. > > > > How does line-by-line execution run inside a frame? > > There isn't actually line-by-line execution as such, although it can be > very similar. Before the interpreter runs Python code, it compiles it to > byte-code, and then runs the byte-code. A single line of source code > could result in any number of lines of byte code, from zero to an > unlimited number. > > > How does __init__ > > work? I understand you must have __init__. > > You understand wrongly then :-) > > It is normal and common to have an __init__ method, but it is not > compulsory. If your class doesn't need one, you don't need to write it. > > The __init__ method is the initialiser. Think of it as very similar to > the constructor in some other languages, and for now the differences > aren't important. The usual purpose of the __init__ method is to > initialise the instance and set any attributes needed. > > > Is it run before print_time(), > > The __init__ method is called once, when the instance is first created. > So the short answer is, yes, it will run before print_time(). But only > once. > > > if so, why don't I just set self.time = '6:30' instead of > > self.time = time? > > Because then every instance will be set to 6:30, instead of letting you > set each instance to a different time. > > > > -- > Steve > > -- > https://mail.python.org/mailman/listinfo/python-list > -- https://mail.python.org/mailman/listinfo/python-list
How to fill in a dictionary with key and value from a string?
Hello all, I want to create a dictionary. The keys are 26 lowercase letters. The values are 26 uppercase letters. The output should look like: {'a': 'A', 'b': 'B',...,'z':'Z' } I know I can use string.ascii_lowercase and string.ascii_uppercase, but how do I use it exactly? I have tried the following to create the keys: myDict = {} for e in string.ascii_lowercase: myDict[e]=0 But, how to fill in the values? Can I do myDict[0]='A', myDict[1]='B', and so on? Thanks! -- https://mail.python.org/mailman/listinfo/python-list
Re: How to fill in a dictionary with key and value from a string?
Thank you all for the response. What if I have myDict = {'a': 'B', 'b': 'C',...,'z':'A' }? So now, the values are shift by one position. key:abcdefghijklmnopqrstuvwxyz value: BCDEFGHIJKLMNOPQRSTUVWXYZA Can I fill in a key and its corresponding value simultaneously on the fly? Something in the following structure. myDict = {} for i in range(26): myDict[lowercase] = uppercase Thank you! On Sun, Apr 1, 2018 at 1:13 PM, Chris Angelico wrote: > On Mon, Apr 2, 2018 at 3:03 AM, Rustom Mody wrote: > > On Saturday, March 31, 2018 at 4:30:04 PM UTC+5:30, bartc wrote: > >> On 30/03/2018 21:13, C W wrote: > >> > Hello all, > >> > > >> > I want to create a dictionary. > >> > > >> > The keys are 26 lowercase letters. The values are 26 uppercase > letters. > >> > > >> > The output should look like: > >> > {'a': 'A', 'b': 'B',...,'z':'Z' } > >> > >> > I know I can use string.ascii_lowercase and string.ascii_uppercase, > but how > >> > do I use it exactly? > >> > I have tried the following to create the keys: > >> > myDict = {} > >> > for e in string.ascii_lowercase: > >> > myDict[e]=0 > >> > >> If the input string S is "cat" and the desired output is {'c':'C', > >> 'a':'A', 't':'T'}, then the loop might look like this: > >> > >> D = {} > >> for c in S: > >> D[c] = c.upper() > >> > >> print (D) > >> > >> Output: > >> > >> {'c': 'C', 'a': 'A', 't': 'T'} > > > > As does… > >>>> {c: c.upper() for c in s} > > {'a': 'A', 'c': 'C', 't': 'T'} : dict > > > > [Recent pythons; not sure when dict-comprehensions appeared] > > 3.0, and also backported to 2.7. So go ahead and use 'em. > > https://www.python.org/dev/peps/pep-0274/ > > ChrisA > -- > https://mail.python.org/mailman/listinfo/python-list > -- https://mail.python.org/mailman/listinfo/python-list
Re: How to fill in a dictionary with key and value from a string?
A different but related question: myDict = dict(zip(string.ascii_lowercase + string.ascii_uppercase, string.ascii_lowercase + string.ascii_uppercase)) >myDict {'A': 'A', 'B': 'B', 'C': 'C',...,'w': 'w', 'x': 'x', 'y': 'y', 'z': 'z'} Why are the keys sorted from upper case to lower case? I asked for lower case first, then upper case. On Sun, Apr 1, 2018 at 8:52 PM, C W wrote: > Thank you all for the response. > > What if I have myDict = {'a': 'B', 'b': 'C',...,'z':'A' }? So now, the > values are shift by one position. > > key:abcdefghijklmnopqrstuvwxyz > value: BCDEFGHIJKLMNOPQRSTUVWXYZA > > Can I fill in a key and its corresponding value simultaneously on the fly? > > Something in the following structure. > > myDict = {} > for i in range(26): >myDict[lowercase] = uppercase > > Thank you! > > On Sun, Apr 1, 2018 at 1:13 PM, Chris Angelico wrote: > >> On Mon, Apr 2, 2018 at 3:03 AM, Rustom Mody >> wrote: >> > On Saturday, March 31, 2018 at 4:30:04 PM UTC+5:30, bartc wrote: >> >> On 30/03/2018 21:13, C W wrote: >> >> > Hello all, >> >> > >> >> > I want to create a dictionary. >> >> > >> >> > The keys are 26 lowercase letters. The values are 26 uppercase >> letters. >> >> > >> >> > The output should look like: >> >> > {'a': 'A', 'b': 'B',...,'z':'Z' } >> >> >> >> > I know I can use string.ascii_lowercase and string.ascii_uppercase, >> but how >> >> > do I use it exactly? >> >> > I have tried the following to create the keys: >> >> > myDict = {} >> >> > for e in string.ascii_lowercase: >> >> > myDict[e]=0 >> >> >> >> If the input string S is "cat" and the desired output is {'c':'C', >> >> 'a':'A', 't':'T'}, then the loop might look like this: >> >> >> >> D = {} >> >> for c in S: >> >> D[c] = c.upper() >> >> >> >> print (D) >> >> >> >> Output: >> >> >> >> {'c': 'C', 'a': 'A', 't': 'T'} >> > >> > As does… >> >>>> {c: c.upper() for c in s} >> > {'a': 'A', 'c': 'C', 't': 'T'} : dict >> > >> > [Recent pythons; not sure when dict-comprehensions appeared] >> >> 3.0, and also backported to 2.7. So go ahead and use 'em. >> >> https://www.python.org/dev/peps/pep-0274/ >> >> ChrisA >> -- >> https://mail.python.org/mailman/listinfo/python-list >> > > -- https://mail.python.org/mailman/listinfo/python-list
Re: How to fill in a dictionary with key and value from a string?
I am using Python 3.6. I ran the those lines and got a sorted dictionary by keys. On Sun, Apr 1, 2018 at 9:38 PM, Chris Angelico wrote: > On Mon, Apr 2, 2018 at 11:34 AM, C W wrote: > > A different but related question: > > > > myDict = dict(zip(string.ascii_lowercase + string.ascii_uppercase, > > string.ascii_lowercase + string.ascii_uppercase)) > >>myDict > > {'A': 'A', 'B': 'B', 'C': 'C',...,'w': 'w', 'x': 'x', 'y': 'y', 'z': 'z'} > > > > Why are the keys sorted from upper case to lower case? I asked for lower > > case first, then upper case. > > > > What version of which Python interpreter are you using? Dictionaries > aren't sorted by definition, but sometimes they do retain order. > > ChrisA > -- > https://mail.python.org/mailman/listinfo/python-list > -- https://mail.python.org/mailman/listinfo/python-list
Re: How to fill in a dictionary with key and value from a string?
Thank you Steven. I am frustrated that I can't enumerate a dictionary by position index. Maybe I want to shift by 2 positions, 5 positions... I want to know/learn how to manipulate dictionary with loop and by its position location. On Sun, Apr 1, 2018 at 10:02 PM, Steven D'Aprano < steve+comp.lang.pyt...@pearwood.info> wrote: > On Sun, 01 Apr 2018 20:52:35 -0400, C W wrote: > > > Thank you all for the response. > > > > What if I have myDict = {'a': 'B', 'b': 'C',...,'z':'A' }? So now, the > > values are shift by one position. > > > > key:abcdefghijklmnopqrstuvwxyz > > value: BCDEFGHIJKLMNOPQRSTUVWXYZA > > > > Can I fill in a key and its corresponding value simultaneously on the > > fly? > > Of course. > > myDict = dict(zip("abcdefghijklmnopqrstuvwxyz", > "BCDEFGHIJKLMNOPQRSTUVWXYZA")) > > > > -- > Steve > > -- > https://mail.python.org/mailman/listinfo/python-list > -- https://mail.python.org/mailman/listinfo/python-list
Re: How to fill in a dictionary with key and value from a string?
Yes, you see right through me! I was able to conquer it, there's probably better ways: self.myDict = dict(zip(string.ascii_lowercase + string.ascii_uppercase, string.ascii_lowercase[shift:26] + string.ascii_lowercase[:shift] + string.ascii_uppercase[shift:26] + string.ascii_uppercase[:shift])) How to debug a particular chunk of code? Everything in OOP is self.myDict, self.shift_dict. So, I must run the entire code to test. I just want to try myDict('hello', 4), shift_dict(4), like how you would do in C language. Thank you! On Sun, Apr 1, 2018 at 11:13 PM, Steven D'Aprano < steve+comp.lang.pyt...@pearwood.info> wrote: > On Sun, 01 Apr 2018 22:24:31 -0400, C W wrote: > > > Thank you Steven. I am frustrated that I can't enumerate a dictionary by > > position index. > > Why do you care about position index? > > > Maybe I want to shift by 2 positions, 5 positions... > > Sounds like you are trying to program the Caesar Shift cipher, am I right? > > You probably should be manipulating *strings*, not dicts. Do these > examples help? > > py> import string > py> letters = string.ascii_lowercase > py> letters > 'abcdefghijklmnopqrstuvwxyz' > py> letters[1:] + letters[:1] > 'bcdefghijklmnopqrstuvwxyza' > py> letters[5:] + letters[:5] > 'fghijklmnopqrstuvwxyzabcde' > py> letters[23:] + letters[:23] > 'xyzabcdefghijklmnopqrstuvw' > > > Slice your strings into the order that you want, then put them in a dict > for fast lookups by character. > > > > I want to know/learn how to manipulate dictionary with loop and by its > > position location. > > Dict entries don't have a position location except by accident, or in > sufficiently new versions of Python, by insertion order. > > If you want to process dict entries in a specific order, operate on the > dict in whichever order you want: > > ordered_keys = 'azbycxdwevfugthsirjqkplomn' > for k in ordered_keys: > print(mydict[k]) > > > In Python 3.7, dicts will keep their insertion order, so long as you > don't delete any keys. > > > > -- > Steve > > -- > https://mail.python.org/mailman/listinfo/python-list > -- https://mail.python.org/mailman/listinfo/python-list
In numpy, why is it ok to do matrix.mean(), but not ok to do matrix.median()?
Hello everyone, In numpy, why is it ok to do matrix.mean(), but not ok to do matrix.median()? To me, they are two of many summary statistics. So, why median() is different? Here's an example code, import numpy as np matrix = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) # find the mean np.mean(matrix) # ok matrix.mean() # ok # find the median np.median(matrixA) # ok matrix.median()# throws error message Also, why have two of the same thing: np.mean(matrix) and matrix.mean()? When to use which one? The documentation below looks almost identical! What am I missing here? [1] Median documentation: https://docs.scipy.org/doc/numpy-1.14.0/reference/generated/numpy.median.html [2] Mean documentation: https://docs.scipy.org/doc/numpy-1.14.0/reference/generated/numpy.mean.html Thank you so much, M -- https://mail.python.org/mailman/listinfo/python-list
Re: In numpy, why is it ok to do matrix.mean(), but not ok to do matrix.median()?
It's interesting how mean() can be implemented, but median() will break other packages. So, the default way in numpy is to use functions, not methods? When I first learned Python, I was told to create an object and to play around, there are methods for that object. List has list methods, tuple has tuple methods, etc. Now, the default way in numpy is to use function instead of methods? I'm confused. What happened to object-oriented programming? Thanks, -M On Tue, May 1, 2018 at 3:38 PM, Thomas Jollans wrote: > On 01/05/18 19:57, C W wrote: > > matrix.median()# throws error message > > READ error messages. At the very least, quote error messages when asking > questions somewhere like here. There I was, wondering why the numpy docs > didn't mention ndarray.median when you were clearly using it... > > Anyway, > > > Hello everyone, > > > > In numpy, why is it ok to do matrix.mean(), but not ok to do > > matrix.median()? To me, they are two of many summary statistics. So, why > > median() is different? > > First, this is how it's different: the method ndarray.median simply does > not exist. > > Now, of course, most numpy functions don't have method versions, so > there's nothing special about median here. However, as you quite rightly > point out, median would be "a good fit". > > As with most things that are "a bit odd" about numpy this probably boils > to "historical reasons". > > numpy mostly goes back to an earlier package called "Numeric". Numeric's > array did not have methods like mean(). Early (anno 2005) numpy also > incorporated features from a package called "numarray"; one of these > features were array methods like ".mean". numarray did not have a > .median method, though it *did* have a function numarray.mlab.median. So > far, so good. ndarray.mean *must* exist for compatibility reasons, > ndarray.median need not. > > So why not add it later? Other methods have been added, after all. Well, > for starters, "who cares?". Most of numpy is functions; the methods are > nice, but not that important. The other obstacle is that numpy.median is > implemented in Python, not in C. For historical reasons™, it has to stay > that way. They tried to change it in 2014, but that broke some other > packages... > > > > > > Here's an example code, > > > > import numpy as np > > matrix = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) > > > > # find the mean > > np.mean(matrix) # ok > > matrix.mean() # ok > > > > # find the median > > np.median(matrixA) # ok > > > > > > > Also, why have two of the same thing: np.mean(matrix) and matrix.mean()? > > When to use which one? > > > > The documentation below looks almost identical! What am I missing here? > > [1] Median documentation: > > https://docs.scipy.org/doc/numpy-1.14.0/reference/ > generated/numpy.median.html > > [2] Mean documentation: > > https://docs.scipy.org/doc/numpy-1.14.0/reference/ > generated/numpy.mean.html > > > > > > Thank you so much, > > > > M > > > > -- > https://mail.python.org/mailman/listinfo/python-list > -- https://mail.python.org/mailman/listinfo/python-list
Re: In numpy, why is it ok to do matrix.mean(), but not ok to do matrix.median()?
Thanks, Chris. That makes sense. The len() example is great! On Tue, May 1, 2018 at 10:37 PM, Chris Angelico wrote: > On Wed, May 2, 2018 at 12:22 PM, C W wrote: > > It's interesting how mean() can be implemented, but median() will break > > other packages. > > > > So, the default way in numpy is to use functions, not methods? > > > > When I first learned Python, I was told to create an object and to play > > around, there are methods for that object. List has list methods, tuple > has > > tuple methods, etc. > > > > Now, the default way in numpy is to use function instead of methods? I'm > > confused. What happened to object-oriented programming? > > Even outside of numpy, a lot of Python uses functions, not methods. > One good reason for this is that a function can accept a wide variety > of data types as its argument; for instance, len() accepts many > things, not just lists. Some things are done with methods, others with > stand-alone functions. There are design choices each way. > > ChrisA > -- > https://mail.python.org/mailman/listinfo/python-list > -- https://mail.python.org/mailman/listinfo/python-list
In Pandas, can you do groupby in on two different datasets?
Dear all, I want find the average ratings of movies by movieId. Below is ratings.head() of the dataset. > ratings.head() userId movieId rating timestamp parsed_time 0 12 3.5 1112486027 2005-04-02 23:53:47 1 1 29 3.5 1112484676 2005-04-02 23:31:16 2 1 32 3.5 1112484819 2005-04-02 23:33:39 3 1 47 3.5 1112484727 2005-04-02 23:32:07 4 1 50 3.5 1112484580 2005-04-02 23:29:40 I'm trying two methods: Method 1 (makes sense) > ratings[['movieId', 'rating']].groupby('rating').mean() This returns dataframe, it's the most common. Method 2 (confusing) > ratings.rating.groupby(ratings.movieId).mean() movieId 13.921240 23.211977 33.151040 42.861393 53.064592 Name: rating, dtype: float64 What going on in method 2? It's calling ratings dataset twice. First in ratings.rating, it restricts the working dataset to only rating column. Then, it groups by ratings.movieId, but how does it know there is movieId. Didn't we just restrict the data to rating column only? Thanks in advance! -- https://mail.python.org/mailman/listinfo/python-list
What data types does matplotlib pyplot take?
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? Is there an official documentation that lists this? I have seen this official documentation: https://pandas.pydata.org/pandas-docs/stable/visualization.html But it does not specify data types. I would appreciate it if someone can point it out. Thank you! -- https://mail.python.org/mailman/listinfo/python-list
Re: Python list vs google group
I recently posted two questions, but never got any replies. I am still wondering if it was ever posted, or maybe the question was too trivial? I think someone would have at least shouted if it was too trivial or off-topic, right? On Fri, Jun 15, 2018 at 12:03 PM, Mark Lawrence wrote: > On 15/06/18 16:47, T Berger wrote: > >> On Friday, June 15, 2018 at 11:31:47 AM UTC-4, Alister wrote: >> >> it certainly seems to be the source of most SPAM >>> as such some users of this list/newsgroup call it what you like block all >>> posts from google groups >>> >> >> But you don't think you get more replies to a question posted here than >> emailed to the list? The forum and the email list are supposed to be >> different access routes to the same content, but I don't find that to be >> the case. I replied to a post via email, but my reply did not show up on >> this forum. >> >> Tamara >> >> > For the third and final time, just get a (semi-)decent email client/news > reader/whatever it's called, point it at news.gmane.org and read this > forum, hundreds of other python forums and thousands of other technical > forums with no problems at all. No cluttered inbox so no need to filter > anything. I happen to use thunderbird, there are umpteen other choices. > > -- > My fellow Pythonistas, ask not what our language can do for you, ask > what you can do for our language. > > Mark Lawrence > > -- > https://mail.python.org/mailman/listinfo/python-list > -- https://mail.python.org/mailman/listinfo/python-list
Why list.reverse() modifies the list, but name.replace() does not modify the string?
Hello all, I am learning the basics of Python. How do I know when a method modifies the original object, when it does not. I have to exmaples: Example 1: > L = [3, 6, 1,4] > L.reverse() > L [4, 1, 6, 3] This changes the original list. Example 2: > name = "John Smith" > name.replace("J", j") > name 'John Smith' This does not change the original string. Why the two examples produce different results? As a beginner, I find this confusing. How do you do it? Thank you! -- https://mail.python.org/mailman/listinfo/python-list
Why list.reverse() modifies the list, but name.replace() does not
Hello all, I am learning the basics of Python. How do I know when a method modifies the original object, when it does not. I have to exmaples: Example 1: > L = [3, 6, 1,4] > L.reverse() > L [4, 1, 6, 3] This changes the original list. Example 2: > name = "John Smith" > name.replace("J", j") > name 'John Smith' This does not change the original string. Why the two examples produce different results? As a beginner, I find this confusing. How do you do it? Thank you! -- https://mail.python.org/mailman/listinfo/python-list
I have anaconda, but Pycharm can't find it
Hello all, I am a first time PyCharm user. I have Python 3 and Anaconda installed. They work together on Sublime Text, but not on Pycharm. Pycharm tells me it cannot find modules numpy, matplotlib, etc. What should I do? I tried to set the interpreter environment, and a few other options, none seem to work. This is the typical solution, but it does not work https://stackoverflow.com/questions/35623776/import-numpy-on-pycharm Thanks, -Mike -- https://mail.python.org/mailman/listinfo/python-list
Spam levels.
I've been reading a limited range of Usenet groups since the late 1980s, and until the recent problems in comp.lang.python had never bothered with any sort of filtering; it's easier just to ignore people. However, the sheer volume of spam in comp.lang.python finally defeated me, so I set up a filter in my leafnode NNTP server, which pulls from eternal-september and gmane (read-only). The results for the last few weeks are below: Jan 20 15:34:39 comp.lang.python: 50 articles fetched, 71 killed Jan 21 14:21:30 comp.lang.python: 25 articles fetched, 18 killed Jan 26 13:04:40 comp.lang.python: 85 articles fetched, 276 killed Jan 28 22:58:42 comp.lang.python: 83 articles fetched, 184 killed Jan 29 16:07:11 comp.lang.python: 41 articles fetched, 52 killed Jan 30 16:57:03 comp.lang.python: 57 articles fetched, 56 killed Jan 31 16:52:01 comp.lang.python: 39 articles fetched, 87 killed Feb 1 16:02:49 comp.lang.python: 39 articles fetched, 73 killed Feb 2 14:39:46 comp.lang.python: 43 articles fetched, 57 killed Feb 3 18:17:55 comp.lang.python: 19 articles fetched, 108 killed Feb 4 15:28:03 comp.lang.python: 36 articles fetched, 122 killed Feb 5 15:26:08 comp.lang.python: 45 articles fetched, 79 killed Feb 6 16:29:40 comp.lang.python: 68 articles fetched, 93 killed Feb 7 16:43:26 comp.lang.python: 32 articles fetched, 118 killed Feb 8 16:01:14 comp.lang.python: 41 articles fetched, 100 killed Feb 9 17:06:09 comp.lang.python: 47 articles fetched, 201 killed giving the totals: Kept: 750 articles Killed: 1695 articles Until the last few days the spammers were using a fixed format, but recently I've had to play whack-a-mole with filtering, so the Killed total is probably underestimated by ten or twenty posts. No other groups (in the limited set which I read) have the problem, and I don't understand why the spammers neither spam a range of groups, nor change their adddresses more frequently. It may be that destroying comp.lang.python is their actual objective. Either way, a depressing state of affairs. Will -- "As democracy is perfected, the office of the president represents, more and more closely, the inner soul of the people. On some great and glorious day, the plain folks of the land will reach their heart's desire at last, and the White House will be occupied by a downright fool and a complete narcissistic moron." -- H. L. Mencken. -- https://mail.python.org/mailman/listinfo/python-list
Respam levels.
Having run a check for straightforward spam, I now find that there's a site editing and reposting non-spam posts. An example of the changed headers follows: Original post headers: > > From c...@seckford.org Sun Feb 11 23:23:22 2018 > Path: > eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail > Message-ID: <4sd3le-ct4@tanner.seckford.org> > From: C W Rose > Newsgroups: comp.lang.python > Subject: Spam levels. > Date: Sat, 10 Feb 2018 14:57:40 + > Lines: 49 > Organization: None > Injection-Info: reader02.eternal-september.org; > posting-host="208e6410f66c7dd789dea67159b51bb7"; > logging-data="6406"; mail-complaints-to="ab...@eternal-september.org"; > posting-account="U2FsdGVkX18su+yG7dqCpnqChqoPIY0JNXRwgNWzvcs=" > User-Agent: tin/2.0.1-20111224 ("Achenvoir") (UNIX) (Linux/3.10.79-gentoo-1 > (i686)) > Cancel-Lock: sha1:H7zOidR0ivbNjqiWUB6DSoMMYu8= > Xref: tanner.seckford.org comp.lang.python:139461 > Repost headers: > > From C Sun Feb 11 23:22:54 2018 > Path: > eternal-september.org!reader02.eternal-september.org!feeder.eternal-september.org!aioe.org!news.bbs.geek.nz!.POSTED.agency.bbs.geek.nz!not-for-mail > Message-ID: <847574...@f38.n261.z1.binkp.net> > From: C W Rose (C W Rose) > Newsgroups: comp.lang.python > Subject: Spam levels. > Date: Sat, 10 Feb 2018 14:57:40 +1200 > Organization: fsxNet Usenet Gateway | bbs.nz/#fsxNet > Mime-Version: 1.0 > Content-Type: text/plain; charset=us-ascii > Content-Transfer-Encoding: 7bit > Injection-Info: news.bbs.geek.nz; > posting-host="M6YmRdZYyc42DJk0lNlt/X4dpP4dzvceBNabSmESN3E"; > logging-data="24378"; mail-complaints-to="ab...@news.bbs.geek.nz" > User-Agent: VSoup v1.2.9.47Beta [95/NT] > X-MailConverter: SoupGate-Win32 v1.05 > X-Comment-To: All > Xref: tanner.seckford.org comp.lang.python:139479 Looking at my current comp.lang.python news spool, 182 out of 683 messages have been reposted by news.bbs.geek.nz; I haven't checked if they are all duplicates. The reformatting of the body of message is to date trivial, just a reduction in line length. This may be the result of a misconfigured spam filter, or an actual spam attack; anyway, I've now filtered news.bbs.geek.nz from my feed. Will -- "When we look around us, this is what we find, The hope that springs eternal, springs right up your behind." -- Ian Dury -- https://mail.python.org/mailman/listinfo/python-list
Re: Filtering computer.lang.python
Thomas Jollans wrote: > > Welcome to python-list/comp.lang.python! > > This isn't originally a Google group. Google just mirrors the old USENET > group, which is awash with spam. > > There is also a mailing list version of this group (posts are mirrored > both ways) at https://mail.python.org/mailman/listinfo/python-list > > The mailing list has proper spam filtering and some moderation. None (or > barely any) of the regulars use Google Groups. Some people use USENET > directly and maintain their own extensive filtering regime to make it > readable. Probably most of us use the mailing list, because it's just so > much nicer! > > -- Thomas I fetch comp.lang.python from eternal.september with leafnode, and after 30 years of Usenet I recently had to install a news filter to remove the garbage. After the initial flurry the filter doesn't need much updating, but here's why it's necessary: Feb 1 comp.lang.python: 39 articles fetched 73 killed Feb 2 comp.lang.python: 43 articles fetched 57 killed Feb 3 comp.lang.python: 19 articles fetched 108 killed Feb 4 comp.lang.python: 36 articles fetched 122 killed Feb 5 comp.lang.python: 45 articles fetched 79 killed Feb 6 comp.lang.python: 68 articles fetched 93 killed Feb 7 comp.lang.python: 32 articles fetched 118 killed Feb 8 comp.lang.python: 41 articles fetched 100 killed Feb 9 comp.lang.python: 47 articles fetched 201 killed Feb 10 comp.lang.python: 44 articles fetched 137 killed Feb 11 comp.lang.python: 36 articles fetched 130 killed Feb 12 comp.lang.python: 13 articles fetched 79 killed Feb 13 comp.lang.python: 18 articles fetched 65 killed Feb 14 comp.lang.python: 34 articles fetched 72 killed Feb 15 comp.lang.python: 15 articles fetched 63 killed Feb 16 comp.lang.python: 14 articles fetched 72 killed Feb 17 comp.lang.python: 50 articles fetched 62 killed Feb 18 comp.lang.python: 37 articles fetched 35 killed Feb 19 comp.lang.python: 58 articles fetched 57 killed Feb 20 comp.lang.python: 71 articles fetched 46 killed Feb 21 comp.lang.python: 63 articles fetched 95 killed Feb 22 comp.lang.python: 35 articles fetched 91 killed Feb 23 comp.lang.python: 38 articles fetched 91 killed Feb 25 comp.lang.python: 51 articles fetched 153 killed Feb 26 comp.lang.python: 70 articles fetched 89 killed Feb 27 comp.lang.python: 64 articles fetched 68 killed Mar 1 comp.lang.python: 98 articles fetched 133 killed Mar 2 comp.lang.python: 65 articles fetched 110 killed Mar 3 comp.lang.python: 38 articles fetched 113 killed Mar 4 comp.lang.python: 31 articles fetched 16 killed Mar 5 comp.lang.python: 51 articles fetched 104 killed Mar 6 comp.lang.python: 46 articles fetched 40 killed Mar 7 comp.lang.python: 18 articles fetched 71 killed Mar 8 comp.lang.python: 44 articles fetched 85 killed Mar 9 comp.lang.python: 43 articles fetched 65 killed Mar 10 comp.lang.python: 16 articles fetched 39 killed Mar 11 comp.lang.python: 25 articles fetched 59 killed Mar 13 comp.lang.python: 43 articles fetched 186 killed Mar 14 comp.lang.python: 20 articles fetched 76 killed Mar 15 comp.lang.python: 32 articles fetched 33 killed Mar 16 comp.lang.python: 16 articles fetched 79 killed Mar 17 comp.lang.python: 11 articles fetched 69 killed Mar 18 comp.lang.python: 4 articles fetched 70 killed Mar 19 comp.lang.python: 10 articles fetched 67 killed Mar 20 comp.lang.python: 42 articles fetched 33 killed Mar 21 comp.lang.python: 43 articles fetched 77 killed Mar 22 comp.lang.python: 14 articles fetched 35 killed Mar 23 comp.lang.python: 37 articles fetched 39 killed Mar 26 comp.lang.python: 139 articles fetched 144 killed Mar 27 comp.lang.python: 83 articles fetched 86 killed Mar 28 comp.lang.python: 39 articles fetched 45 killed Mar 29 comp.lang.python: 12 articles fetched 29 killed Mar 31 comp.lang.python: 67 articles fetched 125 killed for totals of 2168 fetched and 4384 killed; that is, the group is now 2/3 spam and the volume doesn't seem to be decreasing. I don't understand why other groups gatewayed to Google Groups aren't spammed, but from a limited sample they don't seem to be. Will -- "That which is hateful to you, do not do to your fellow. That is the whole Torah; the rest is commentary." -- Hillel the Elder -- https://mail.python.org/mailman/listinfo/python-list
Re: Spam levels.
m wrote: > W dniu 10.02.2018 o 15:57, C W Rose pisze: >> No other groups (in the limited set which I read) have the problem, >> and I don't understand why the spammers neither spam a range of >> groups, nor change their adddresses more frequently. It may be >> that destroying comp.lang.python is their actual objective. >> >> Either way, a depressing state of affairs. > > The sad thing is, that your post is unseen, because of spam :S > > I also almost stopped reading c.l.python, because of enormous spam > levels. Do I have any option to read it without spam, other than launch > my own filtering NNTP server and do whack the mole game for myself? > > Maybe join forces and establish such server for public use? > The situation is getting worse: comp.lang.python messages 29 Jan - 14 May 2018 Fetched: 3081 Killed: 6616 Valid: 31.77 % Almost all of the garbage is coming from the "Case Solutions" poster, with a hotmail address. He's said himself that he doesn't read the group, and there's really no point to endless reposting in a newsgroup with no relevance to the posts, so it's just mindless vandalism. He doesn't change addresses or headers much, so the filter seldom needs updating; however, I think comp.lang.python is reaching the end of the line. comp.lang.c has less overwhelming problems, due to a single obsessive: comp.lang.c messages 29 Jan - 14 May 2018 Fetched: 3969 Killed: 618 Valid: 86.52 % If you are using Linux, leafnode is easy to set up, and has enough filtering to keep comp.lang.python readable. I pull from news.eternal-september.org and news.gmane.org (though I don't know how much longer gmane will last). Both are free. Will -- "It is very disappointing that mindless individuals are vandalising the Larkin toads in Hull." A police spokesman -- https://mail.python.org/mailman/listinfo/python-list
Re: Python indentation (3 spaces)
Ryan Johnson wrote: > The point that OP is trying to make is that a fixed standard that is > distinguishable from the even-spacing Tab-length convention in code and > text editors will establish a level of trust between the end developer and > upstream developers or co-developers who may not have the same development > environment. For example, the first Python library I ever tried to use was > poorly maintained and had spaces on one line with tabs on the next, and the > author mixed naming conventions and syntax from Python 2 and 3 in his code. > That type of experience doesn’t exactly instill trust in the coding > language’s standards, when a noob tries to use a library they found and > ends up having to debug weird errors with weirder error messages on the > first project they do. The view of the Python Gods (TM) is that significant whitespace make Python much easier to use, particularly for the inexperienced. If you disagree, then use another language. (Leibnitz had some snappy phrases on the subject of Theodicy, which explain the matter clearly.) Will -- https://mail.python.org/mailman/listinfo/python-list