Re: Where is the error?
When i try to open a python script it either says theres no ctk module or no pip On Sun, Aug 6, 2023, 3:51 PM Peter J. Holzer via Python-list < python-list@python.org> wrote: > Mostly, error messages got a lot better in Python 3.10, but this one had > me scratching my head for a few minutes. > > Consider this useless and faulty script: > > > r = { > "x": (1 + 2 + 3) > "y": (4 + 5 + 6) > "z": (7 + 8 + 9) > } > > > Python 3.9 (and earlier) reports: > > > File "/home/hjp/tmp/foo", line 3 > "y": (4 + 5 + 6) > ^ > SyntaxError: invalid syntax > > > This isn't great, but experience with lots of programming languages > tells me that an error is noticed where or after it actually occurs, so > it's easy to see that there is a comma missing just before the "y". > > Python 3.10 and 3.11 report: > > > File "/home/hjp/tmp/foo", line 2 > "x": (1 + 2 + 3) > ^^ > SyntaxError: invalid syntax. Perhaps you forgot a comma? > > > The error message is now a lot better, of course, but the fact that it > points at the expression *before* the error completely threw me. The > underlined expression is clearly not missing a comma, nor is there an > error before that. My real program was a bit longer of course, so I > checked the lines before that to see if I forgot to close any > parentheses. Took me some time to notice the missing comma *after* the > underlined expression. > > Is this "clairvoyant" behaviour a side-effect of the new parser or was > that a deliberate decision? > > hp > > -- >_ | Peter J. Holzer| Story must make more sense than reality. > |_|_) || > | | | h...@hjp.at |-- Charles Stross, "Creative writing > __/ | http://www.hjp.at/ | challenge!" > -- > https://mail.python.org/mailman/listinfo/python-list > -- https://mail.python.org/mailman/listinfo/python-list
Re: Where is the error?
On 07Aug2023 08:02, Barry wrote: On 7 Aug 2023, at 05:28, Cameron Simpson via Python-list wrote: Used to use a Pascal compiler once which was uncannily good at suggesting where you'd missing a semicolon. Was that on DEC VMS? It was a goal at DEC for its compilers to do this well. No, a PDP-11 using V7 UNIX. They could output the errors in a machine readable format to allow editors to auto fix. I am learning rust and it is very good at suggesting fixes. There is a command to apply fixes automatically, cargo fix. Neat. Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list
Re: Where is the error?
> On 7 Aug 2023, at 05:28, Cameron Simpson via Python-list > wrote: > > Used to use a Pascal compiler once which was uncannily good at suggesting > where you'd missing a semicolon. Was that on DEC VMS? It was a goal at DEC for its compilers to do this well. They could output the errors in a machine readable format to allow editors to auto fix. I am learning rust and it is very good at suggesting fixes. There is a command to apply fixes automatically, cargo fix. Barry -- https://mail.python.org/mailman/listinfo/python-list
Re: Where is the error?
On 06Aug2023 22:41, Peter J. Holzer wrote: Mostly, error messages got a lot better in Python 3.10, but this one had me scratching my head for a few minutes. Consider this useless and faulty script: r = { "x": (1 + 2 + 3) "y": (4 + 5 + 6) "z": (7 + 8 + 9) } [...] Python 3.10 and 3.11 report: File "/home/hjp/tmp/foo", line 2 "x": (1 + 2 + 3) ^^ SyntaxError: invalid syntax. Perhaps you forgot a comma? The error message is now a lot better, of course, but the fact that it points at the expression *before* the error completely threw me. The underlined expression is clearly not missing a comma, nor is there an error before that. Well, it's hard to underline a token which isn't present. But maybe the message could be more evocative: SyntaxError: invalid syntax. Perhaps you forgot a comma after the underlined code? Is this "clairvoyant" behaviour a side-effect of the new parser or was that a deliberate decision? I have the vague impression the new parser enabled the improved reporting. Used to use a Pascal compiler once which was uncannily good at suggesting where you'd missing a semicolon. Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list
Re: Where is the error?
On 07/08/2023 08.41, Peter J. Holzer via Python-list wrote: Mostly, error messages got a lot better in Python 3.10, but this one had me scratching my head for a few minutes. ... The error message is now a lot better, of course, but the fact that it points at the expression *before* the error completely threw me. The underlined expression is clearly not missing a comma, nor is there an error before that. My real program was a bit longer of course, so I checked the lines before that to see if I forgot to close any parentheses. Took me some time to notice the missing comma *after* the underlined expression. Is this "clairvoyant" behaviour a side-effect of the new parser or was that a deliberate decision? Found myself chuckling at this - not to be unkind, but because can easily imagine such confusion on my own part. The issue of unhelpful error messages or information aimed at a similar but different context, has been the story of our lives. Advice to trainees has always been to cast-about looking for the error - rather than taking the line-number as a precise location. Have made a note to avoid advising folk to work 'backwards'! Meantime (back at the ranch?), haven't experienced this. Using an IDE means all such stuff is reported, as one types, through highlights and squiggly lines (which should(?) be considered and cleared - before pressing the GO-button). In this case, the PyCharm* editor adds red-squiggles where the commas should have been. Hovering the cursor over a squiggle, the IDE reports "',' expected"! Its PythonConsole behaves similarly (without offering a 'hover'). Plus, even after the closing brace, it continues to assume a multi-line compound-statement (and thus won't execute, per expected REPL behavior). Way-back (grey-beard time!) when we submitted card-decks of code to be compiled over-night, one idea to avoid expensive, trivial errors/eras; was that spelling-checkers should be built-in to compilers, eg to auto-magically correct typos, eg AFF 1 TO TOTAL instead of: ADD 1 TO TOTAL These days, we can look at code from two or more years ago, 'produced' by ChatGPT (et al), aka "The Stochastic Parrot". There is some thought that artificial 'intelligence' will one-day be able to do the coding for us/predict what is required/act as a crystal ball... Speaking of which, and just because I could, here's what Chat-GPT had to say when I asked "what's wrong with ...": «The issue in the given Python code is that you're missing commas between the key-value pairs in the dictionary. Commas are required to separate different key-value pairs within a dictionary. Here's the corrected version of the code: ... » Question: If a Chat-AI is built into the IDE (I stripped such out from mine), does it take-over error reporting and diagnosis (and offer the option of replacing with its 'corrected version'?) - rather than requiring an extra copy-paste step, per above? (and need for my assumption of where the error is located) Hope you've exerted copyright over the "clairvoyant" description! * JetBrains kindly sponsor our PUG with a monthly door-prize. -- -- Regards, =dn -- https://mail.python.org/mailman/listinfo/python-list
Where is the error?
Mostly, error messages got a lot better in Python 3.10, but this one had me scratching my head for a few minutes. Consider this useless and faulty script: r = { "x": (1 + 2 + 3) "y": (4 + 5 + 6) "z": (7 + 8 + 9) } Python 3.9 (and earlier) reports: File "/home/hjp/tmp/foo", line 3 "y": (4 + 5 + 6) ^ SyntaxError: invalid syntax This isn't great, but experience with lots of programming languages tells me that an error is noticed where or after it actually occurs, so it's easy to see that there is a comma missing just before the "y". Python 3.10 and 3.11 report: File "/home/hjp/tmp/foo", line 2 "x": (1 + 2 + 3) ^^ SyntaxError: invalid syntax. Perhaps you forgot a comma? The error message is now a lot better, of course, but the fact that it points at the expression *before* the error completely threw me. The underlined expression is clearly not missing a comma, nor is there an error before that. My real program was a bit longer of course, so I checked the lines before that to see if I forgot to close any parentheses. Took me some time to notice the missing comma *after* the underlined expression. Is this "clairvoyant" behaviour a side-effect of the new parser or was that a deliberate decision? hp -- _ | Peter J. Holzer| Story must make more sense than reality. |_|_) || | | | h...@hjp.at |-- Charles Stross, "Creative writing __/ | http://www.hjp.at/ | challenge!" signature.asc Description: PGP signature -- https://mail.python.org/mailman/listinfo/python-list
Re: where is the error?
[EMAIL PROTECTED] wrote: ... And my problem was that the commands worked on windows but not on linux. By the way, shouldn't you be using numpy? I thought numarray was going away by mid-2008 i.e. now. I know, but i'm not sure that it's the problem. It's your job to get certain of some things, and what people are proposing are experiments you can do to find the answer. The problem is yours, the benefit of having the code work will be yours, and you, unlike us, are in a position to perform experiments. Don't be as vague as "the commands worked on windows but not on linux." That kind of statement is usually a flag that you _think_ you typed the same thing. Write a complete, small test program that demonstrates your success on XP. Move the program to Ubuntu (remembering about line endings) via flash drive or something. Run _exactly_ the same program on Ubuntu. If you get a failure, keep trimming the program on Ubuntu til you find the smallest program that breaks. Take it back to XP and make sure it still runs there. Don't give partial version information. I know you have two systems: Ubuntu (who knows what version), python 2.4.3, numarray who knows. The Windows box is running XP, but what service pack? what version of Python on XP? What version of numarray on XP? In collecting all of this information _before_ you ask, you often discover the answer to your question without needing to ask anyone else. If numpy might solve your problem, why avoid trying it simply because it might not do so? Sorry, this a long form of "read smart questions," but it did include some suggestions about how you could find the problem in your particular case. --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Re: where is the error?
> > I think that you mean that diff_temp will be an array of the numberS > (plural) of the lines (rows?) in values array that met the -2 < x < 2 > criterion. Now you want to be able to use diff_temp to get the > corresponding subset of some other array. Am I getting close? I think that you're getting close. I want to get the lines that met the criterion. Diff_temp is an array containing the values of the lines. So bascially, > Now you want to be able to use diff_temp to get the corresponding > subset of some other array. Am I getting close? yes > Perhaps you need something like other_array.take(diff_temp) ? And my problem was that the commands worked on windows but not on linux. > By the way, shouldn't you be using numpy? I thought numarray was going > away by mid-2008 i.e. now. I know, but i'm not sure that it's the problem. Thanks Cedric -- http://mail.python.org/mailman/listinfo/python-list
Re: where is the error?
> > I think that you mean that diff_temp will be an array of the numberS > (plural) of the lines (rows?) in values array that met the -2 < x < 2 > criterion. Now you want to be able to use diff_temp to get the > corresponding subset of some other array. Am I getting close? I think that you're getting close. I want to get the lines that met the criterion. Diff_temp is an array containing the values of the lines. So bascially, > Now you want to be able to use diff_temp to get the corresponding > subset of some other array. Am I getting close? yes > Perhaps you need something like other_array.take(diff_temp) ? And my problem was that the commands worked on windows but not on linux. > By the way, shouldn't you be using numpy? I thought numarray was going > away by mid-2008 i.e. now. I know, but i'm not sure that it's the problem. Thanks Cedric -- http://mail.python.org/mailman/listinfo/python-list
Re: where is the error?
> > I think that you mean that diff_temp will be an array of the numberS > (plural) of the lines (rows?) in values array that met the -2 < x < 2 > criterion. Now you want to be able to use diff_temp to get the > corresponding subset of some other array. Am I getting close? I think that you're getting close. I want to get the lines that met the criterion. Diff_temp is an array containing the values of the lines. So bascially, > Now you want to be able to use diff_temp to get the corresponding > subset of some other array. Am I getting close? yes > Perhaps you need something like other_array.take(diff_temp) ? And my problem was that the commands worked on windows but not on linux. > By the way, shouldn't you be using numpy? I thought numarray was going > away by mid-2008 i.e. now. I know, but i'm not sure that it's the problem. Thanks Cedric -- http://mail.python.org/mailman/listinfo/python-list
Re: where is the error?
> > I think that you mean that diff_temp will be an array of the numberS > (plural) of the lines (rows?) in values array that met the -2 < x < 2 > criterion. Now you want to be able to use diff_temp to get the > corresponding subset of some other array. Am I getting close? I think that you're getting close. I want to get the lines that met the criterion. Diff_temp is an array containing the values of the lines. So bascially, > Now you want to be able to use diff_temp to get the corresponding > subset of some other array. Am I getting close? yes > Perhaps you need something like other_array.take(diff_temp) ? And my problem was that the commands worked on windows but not on linux. > By the way, shouldn't you be using numpy? I thought numarray was going > away by mid-2008 i.e. now. I know, but i'm not sure that it's the problem. Thanks Cedric -- http://mail.python.org/mailman/listinfo/python-list
Re: where is the error?
> > I think that you mean that diff_temp will be an array of the numberS > (plural) of the lines (rows?) in values array that met the -2 < x < 2 > criterion. Now you want to be able to use diff_temp to get the > corresponding subset of some other array. Am I getting close? I think that you're getting close. I want to get the lines that met the criterion. Diff_temp is an array containing the values of the lines. So bascially, > Now you want to be able to use diff_temp to get the corresponding > subset of some other array. Am I getting close? yes > Perhaps you need something like other_array.take(diff_temp) ? And my problem was that the commands worked on windows but not on linux. > By the way, shouldn't you be using numpy? I thought numarray was going > away by mid-2008 i.e. now. I know, but i'm not sure that it's the problem. Thanks Cedric -- http://mail.python.org/mailman/listinfo/python-list
Re: where is the error?
On Jun 27, 10:12 pm, [EMAIL PROTECTED] wrote: > There was an error with the name of the variable I would not ask > this if it was just a question of different variable names ! > Calm down. Stop shouting. It is not evident whether the above means that diff_temp_Stumpf was an error (should have been merely diff_temp) or not. > diff_temp=(logical_and(values[:,5] > -2,values[:,5] < 2)).nonzero() > new_values=values[diff_temp,:] > > Okay, I'm going to try to explain that more specifically that I did. I > have an array called values (size mxn). In this database, I just want > the lines for which the values of the nth row are between two values > (it's the purpose of diff_temp). So diff_temp gets me the number of > the lines for which this latter criteria is right. I think that you mean that diff_temp will be an array of the numberS (plural) of the lines (rows?) in values array that met the -2 < x < 2 criterion. Now you want to be able to use diff_temp to get the corresponding subset of some other array. Am I getting close? > But I'm interested > on the values of the lines corresponding to the number given by > diff_temp. Now you want to be able to use diff_temp to get the corresponding subset of some other array. Am I getting close? Perhaps you need something like other_array.take(diff_temp) ? > > In matlab, I will do > > diff_temp=find(values(:,5) > -2 & values[:,5) <2) > > new_values=values(diff_temp,:) > > Is it clear? Not very, I don't grok matlab. By the way, shouldn't you be using numpy? I thought numarray was going away by mid-2008 i.e. now. HTH, John > Thanks > Cedric -- http://mail.python.org/mailman/listinfo/python-list
Re: where is the error?
There was an error with the name of the variable I would not ask this if it was just a question of different variable names ! diff_temp=(logical_and(values[:,5] > -2,values[:,5] < 2)).nonzero() new_values=values[diff_temp,:] Okay, I'm going to try to explain that more specifically that I did. I have an array called values (size mxn). In this database, I just want the lines for which the values of the nth row are between two values (it's the purpose of diff_temp). So diff_temp gets me the number of the lines for which this latter criteria is right. But I'm interested on the values of the lines corresponding to the number given by diff_temp. In matlab, I will do diff_temp=find(values(:,5) > -2 & values[:,5) <2) new_values=values(diff_temp,:) Is it clear? Thanks Cedric -- http://mail.python.org/mailman/listinfo/python-list
Re: where is the error?
On Jun 27, 7:54 pm, [EMAIL PROTECTED] wrote: > Maybe I didn't explain correctly what i wanted to do. I have a > database and I just want to pick data under a certain criteria. So I > wanted to use a function like nonzero or find or where to find the > line for corresponding to the data following this criteria. So to find > the lines, I used nonzero and it corresponds to the command: > > diff_temp=(logical_and(values[:,5] > -2,values[:,5] < 2)).nonzero() > > so YES it has SOMETHING to do with the question below. > > diff_temp=(array([ 0, 6, 7, 10, 14, 15, 16, 17, 21, 22, > 24, 25, 26, > 27, 31, 32, 33, 36, 37, 38, 39, 40, 41, 42, 46, > 47, > 48, 49, 50, 51, 52, 53, 54, 59, 60, 61, 62, 71, > 72, > 73, 74, 75, 80, 81, 82, 83, 84, 85, 86, 87, 88, > 89, > 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, > 102, >103, 104, 105, 106, 107, 111, 112, 113, 114, 115, 116]),) > > So now I just want to have the data corresponding to those lines. > Thinking that python was a powerful tool, I thought that it was just > possible to assign those line directly in a matrix. So I used the > command: You will need to explain what you mean by "assign those line directly in a matrix". We are not mind-readers, and neither is Python. > > values_matchup=values_Stumpf[diff_temp_Stumpf,:] > > But it didn't work. I'm sure that there is a specific reason. The specific reason is as Gary explained. What you have done is assign the name diff_temp to some expression. This has absolutely nothing to do with diff_temp_Stumpf which is an utterly different name, and as far as we can tell has no referent as all, hence the error message that you got. You may need one of the following solutions: (1) diff_temp_Stumpf = diff_temp (2) def make_diff_temp_thing(values): return (logical_and(v[:,5] > -2,v[:,5] < 2)).nonzero() # much later ... values_matchup = make_temp_thing(values_Stumpf) but it's rather hard to understand what you want ... > But my > concern was that this command works FINE if I use python on windows xp > but doesn't work if I use python on my linux Ubuntu machine. The usual cause of this kind of phenomenon is experimental error e.g. you didn't execute exactly the same statements (not "commands") on Windows as on Linux. > So I > wondered what was wrong and if there is a easy and simple way to get > directly a new array with the data corresponding to a certain > criteria. It might help if you use less abstract phrases than "corresponding to a certain criteria". Can you relate how you would solve this problem in a computer language other that Python? -- http://mail.python.org/mailman/listinfo/python-list
Re: where is the error?
Maybe I didn't explain correctly what i wanted to do. I have a database and I just want to pick data under a certain criteria. So I wanted to use a function like nonzero or find or where to find the line for corresponding to the data following this criteria. So to find the lines, I used nonzero and it corresponds to the command: diff_temp=(logical_and(values[:,5] > -2,values[:,5] < 2)).nonzero() so YES it has SOMETHING to do with the question below. diff_temp=(array([ 0, 6, 7, 10, 14, 15, 16, 17, 21, 22, 24, 25, 26, 27, 31, 32, 33, 36, 37, 38, 39, 40, 41, 42, 46, 47, 48, 49, 50, 51, 52, 53, 54, 59, 60, 61, 62, 71, 72, 73, 74, 75, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 111, 112, 113, 114, 115, 116]),) So now I just want to have the data corresponding to those lines. Thinking that python was a powerful tool, I thought that it was just possible to assign those line directly in a matrix. So I used the command: values_matchup=values_Stumpf[diff_temp_Stumpf,:] But it didn't work. I'm sure that there is a specific reason. But my concern was that this command works FINE if I use python on windows xp but doesn't work if I use python on my linux Ubuntu machine. So I wondered what was wrong and if there is a easy and simple way to get directly a new array with the data corresponding to a certain criteria. Thanks for the help, Cedric -- http://mail.python.org/mailman/listinfo/python-list
Re: where is the error?
[EMAIL PROTECTED] wrote: Hello, I'm trying to assign data into an array with the nonzero function. There is my code. from numarray import * diff_temp=(logical_and(values[:,5] > -2,values[:,5] < 2)).nonzero() Does that have something to do with the question below? This command works fine but when I apply the following, values_matchup=values_Stumpf[diff_temp_Stumpf,:] Clearly, from the error message, the index diff_temp_Stumpf is not one of the allowed types. Have you examined its value? Printed it? Set it equal to a known legal value and tried that line again? First thing: Find out what value that index has, then if it's necessary to ask your question again, include that information and we'll have something to go on in forming an answer. Gary Herron I have this error message: IndexError: each subindex must be either a slice, an integer, Ellipsis, or NewAxis Does someone know what it is the problem? I'm using python2.4.3 on Ubuntu. Using this command with python on windows xp worked fine. Thank you for the help, Cedric -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
where is the error?
Hello, I'm trying to assign data into an array with the nonzero function. There is my code. from numarray import * diff_temp=(logical_and(values[:,5] > -2,values[:,5] < 2)).nonzero() This command works fine but when I apply the following, values_matchup=values_Stumpf[diff_temp_Stumpf,:] I have this error message: IndexError: each subindex must be either a slice, an integer, Ellipsis, or NewAxis Does someone know what it is the problem? I'm using python2.4.3 on Ubuntu. Using this command with python on windows xp worked fine. Thank you for the help, Cedric -- http://mail.python.org/mailman/listinfo/python-list
Where is the error
hello, when i run the following code to Read and tokenize data from a tagged text as follows : from nltk.corpus import brownfrom nltk.tagger import TaggedTokenizerfrom nltk.tokenizer import *tagged_txt_str=open('corpus.txt' ).read()tagged_txt_token=Token(TEXT=tagged_txt_str)TaggedTokenizer.tokenize(tagged_txt_token)print tagged_txt_token i got the following error :Traceback (most recent call last):File "C:\My Documents\TAGGING.PY", line 3, in -toplevel-from nltk.tagger import TaggedTokenizerImportError: cannot import name TaggedTokenizer could anyone help me thanks in advanceenas Yahoo! Music Unlimited - Access over 1 million songs. Try it free.-- http://mail.python.org/mailman/listinfo/python-list