tinker Form question(s)
I am not sure how to post the code for my file here, is copy/paste the best way? Is there another? I understand that attachments are stripped off. """ The following segment of code returns values of "spec". I would like to have it return the associated value of "DataLine" with each spec. It would also be nice to understand how this code works to hold/return the information. In pseudocode, a line something like: DataReturned = DataLine + " " + spec) New_Specs.append(DataReturned) explains what I would like to have returned. """ New_Specs = [] OldSpec = ItemID NewSpec = " " OldLine = ItemID x = 3 y = 0 for lineItem in range(len(ThisList)): DataLine, Spec = GetLineByItem(ThisList[y]) SVRlabel = ttk.Label(window, width = BoxWidth1, text = DataLine) SVRlabel.grid(column = 1, row = x, sticky=tk.W) SVRlabel = ttk.Label(window, width = BoxWidth2, text = Spec) SVRlabel.grid(column = 2, row = x) NewSpec = tk.StringVar() New_Specs.append(NewSpec) SVRCodeEntered = ttk.Entry(window, width = BoxWidth3, textvariable = NewSpec) SVRlabel = ttk.Entry(window, width = BoxWidth3, textvariable = NewSpec) SVRlabel.grid(column = 3, row = x, pady = 5, sticky=tk.W) SVRCodeEntered.grid(column = 3, row = x, pady = 5, padx = 15, sticky=tk.W) SVRCodeEntered.insert(0, OldSpec) x += 1 y += 1 return ([spec.get()for spec in New_Specs]) == Steve = Footnote: Some mornings it just isn't worth chewing through the leather straps. -- https://mail.python.org/mailman/listinfo/python-list
Re: What this error want to say? Can't we use return without function?
On Monday, 7 September 2020 at 12:57:16 UTC+5:30, Python wrote:
> Shivlal Sharma wrote:
> > N = int(input("enter a positive integer:"))
> > coun = 1
> > while (N > 0):
> > coun = coun * N
> > N = N - 1
> > return coun
> > nice = ntime(N)
> > print(nice)
> >
> >
> > error: return outside of the function
> What did you expect return out of a function to even mean?
I mean that can't we use return keyword outside of the function?
--
https://mail.python.org/mailman/listinfo/python-list
Re: What this error want to say? Can't we use return without function?
On Mon, Sep 7, 2020 at 5:36 PM Shivlal Sharma wrote:
>
> On Monday, 7 September 2020 at 12:57:16 UTC+5:30, Python wrote:
> > Shivlal Sharma wrote:
> > > N = int(input("enter a positive integer:"))
> > > coun = 1
> > > while (N > 0):
> > > coun = coun * N
> > > N = N - 1
> > > return coun
> > > nice = ntime(N)
> > > print(nice)
> > >
> > >
> > > error: return outside of the function
> > What did you expect return out of a function to even mean?
> I mean that can't we use return keyword outside of the function?
Well... no. What do you expect it to mean? It's like asking "why can't
I use 'else' without 'if'?" - there'd need to be some meaning for it.
ChrisA
--
https://mail.python.org/mailman/listinfo/python-list
Re: What this error want to say? Can't we use return without function?
On Monday, 7 September 2020 at 13:08:04 UTC+5:30, Chris Angelico wrote:
> On Mon, Sep 7, 2020 at 5:36 PM Shivlal Sharma wrote:
> >
> > On Monday, 7 September 2020 at 12:57:16 UTC+5:30, Python wrote:
> > > Shivlal Sharma wrote:
> > > > N = int(input("enter a positive integer:"))
> > > > coun = 1
> > > > while (N > 0):
> > > > coun = coun * N
> > > > N = N - 1
> > > > return coun
> > > > nice = ntime(N)
> > > > print(nice)
> > > >
> > > >
> > > > error: return outside of the function
> > > What did you expect return out of a function to even mean?
> > I mean that can't we use return keyword outside of the function?
> Well... no. What do you expect it to mean? It's like asking "why can't
> I use 'else' without 'if'?" - there'd need to be some meaning for it.
>
> ChrisA
Ohh, got it. you mean we can't you return without a function, right?
--
https://mail.python.org/mailman/listinfo/python-list
Re: What this error want to say? Can't we use return without function?
On Monday, 7 September 2020 at 13:10:57 UTC+5:30, Shivlal Sharma wrote:
> On Monday, 7 September 2020 at 13:08:04 UTC+5:30, Chris Angelico wrote:
> > On Mon, Sep 7, 2020 at 5:36 PM Shivlal Sharma wrote:
> > >
> > > On Monday, 7 September 2020 at 12:57:16 UTC+5:30, Python wrote:
> > > > Shivlal Sharma wrote:
> > > > > N = int(input("enter a positive integer:"))
> > > > > coun = 1
> > > > > while (N > 0):
> > > > > coun = coun * N
> > > > > N = N - 1
> > > > > return coun
> > > > > nice = ntime(N)
> > > > > print(nice)
> > > > >
> > > > >
> > > > > error: return outside of the function
> > > > What did you expect return out of a function to even mean?
> > > I mean that can't we use return keyword outside of the function?
> > Well... no. What do you expect it to mean? It's like asking "why can't
> > I use 'else' without 'if'?" - there'd need to be some meaning for it.
> >
> > ChrisA
> Ohh, got it. you mean we can't you return without a function, right?
Thank you guys!
--
https://mail.python.org/mailman/listinfo/python-list
Re: Replacement for pygtk?
Akkana Peck writes: > Grant Edwards writes: >> * PyQt -- I run Gtk-centric Linux systems, and the second you try to >>use one Qt widget, it always seems to pull in hundreds of packages >>that take a week to build. > > I haven't generally found that about PyQt. Most KDE apps do pull in > hundreds of packages, but I haven't had to install that many just to > use PyQt. Once you have one Qt app in a Gtk DE, or vice versa, then you have taken most of the hit for packages. I doubt that many people run pure versions of either. -- Pete Forman -- https://mail.python.org/mailman/listinfo/python-list
Re: tinker Form question(s)
Steve wrote: > I am not sure how to post the code for my file here, is copy/paste the > best way? Yes. Try to paste only the relevant parts, or, if possible, post a small self-contained example that can be run by the reader without further editing. > Is there another? I understand that attachments are stripped > off. > > """ > The following segment of code returns values of "spec". > I would like to have it return the associated value of > "DataLine" with each spec. It would also be nice to understand > how this code works to hold/return the information. > > In pseudocode, a line something like: > > DataReturned = DataLine + " " + spec) > New_Specs.append(DataReturned) > > explains what I would like to have returned. > return ([spec.get()for spec in New_Specs]) [spec.get() for spec in New_Specs] is called "list comprehension" and is syntactic sugar for a list-creating loop like result = [] for spec in New_Specs: result.append(spec.get()) The relevant parts of the loop where you set up the GUI and the New_Specs list: > New_Specs = [] > for lineItem in range(len(ThisList)): > DataLine, Spec = GetLineByItem(ThisList[y]) ... > NewSpec = tk.StringVar() > New_Specs.append(NewSpec) First, using range(len(ThisList)) is almost always superfluous as you can iterate over the list directly. In your case: > New_Specs = [] for item in ThisList: > DataLine, Spec = GetLineByItem(item) ... > NewSpec = tk.StringVar() > New_Specs.append(NewSpec) Now, as you need DataLine later-on why not keep a copy? So let's turn New_Specs into a list of StringVar, DataLine tuples: > New_Specs = [] for item in ThisList: > DataLine, Spec = GetLineByItem(item) ... > NewSpec = tk.StringVar() New_Specs.append((NewSpec, DataLine)) When the function terminates (there is a mainloop() missing) you can create and return the result: # long form, with a loop result = [] for spec, dataline in New_Specs: result.append(dataline + " " + spec.get()) return result # alternative using a listcomp: return [dataline + " " + spec.get() for spec, dataline in New_specs] -- https://mail.python.org/mailman/listinfo/python-list
Re: What this error want to say? Can't we use return without function?
On 9/7/2020 3:34 AM, Shivlal Sharma wrote: nice = ntime(N) error: return outside of the function Please copy and paste exact text. Python actually said SyntaxError: 'return' outside function which means that a 'return' outside of a function is a syntax error. -- Terry Jan Reedy -- https://mail.python.org/mailman/listinfo/python-list
What this error want to say? Can't we use return without function?
N = int(input("enter a positive integer:"))
coun = 1
while (N > 0):
coun = coun * N
N = N - 1
return coun
nice = ntime(N)
print(nice)
error: return outside of the function
--
https://mail.python.org/mailman/listinfo/python-list
