Python threading - event
Hello Friends, I got an requirement as stated below, 1. main thread will be running and other event should run parallel In more detail One function will be keep dumping data and other event function should trigger at some event but dumping data should be keep running. Sorry, I can not give any example as I couldn't come up with solution hence am writing here. Kindly support. Regards Prahallad -- https://mail.python.org/mailman/listinfo/python-list
Sum of few numbers by using for and range
Hello!
I need to do what I wrote in the subject but... I don't understand how
could I fix my code... :\
number1 = int( input("Insert the first number:"))
number2 = int( input("Insert the second number:"))
number3 = int( input("Insert the third number:"))
print("Total amount is:")
for x in range(number1,number3):
y = x+x
print(y)
Regards.
^Bart
--
https://mail.python.org/mailman/listinfo/python-list
Re: Sum of few numbers by using for and range
On Mon, Feb 18, 2019 at 3:26 AM ^Bart wrote:
>
> Hello!
>
> I need to do what I wrote in the subject but... I don't understand how
> could I fix my code... :\
>
> number1 = int( input("Insert the first number:"))
> number2 = int( input("Insert the second number:"))
> number3 = int( input("Insert the third number:"))
>
> print("Total amount is:")
>
> for x in range(number1,number3):
> y = x+x
> print(y)
>
When you want homework help, it is extremely useful to post the entire
challenge you were given, not just a one-line summary. What are you
actually expected to do? What are the restrictions?
I suspect, from your last few posts, that you should not be taking
particular challenges, but should instead go back to the basics of how
Python works. Reread the earliest material in your course and make
sure you truly understand what is going on. Try to piece together what
a section of code is doing, step by step. Write down on a piece of
paper what the variables are at each point in the program. Then, AFTER
doing the work manually, run the code and see if you were right.
ChrisA
--
https://mail.python.org/mailman/listinfo/python-list
Re: Python threading - event
On 2019-02-17 09:52, Prahallad Achar wrote: Hello Friends, I got an requirement as stated below, 1. main thread will be running and other event should run parallel In more detail One function will be keep dumping data and other event function should trigger at some event but dumping data should be keep running. Sorry, I can not give any example as I couldn't come up with solution hence am writing here. Use a queue. It's defined in the queue module. -- https://mail.python.org/mailman/listinfo/python-list
Re: Sum of few numbers by using for and range
^Bart, Which course are you attempting? What are you using as learning material? (it seems ineffectual) - further comments interspersed, below:- On 18/02/19 5:30 AM, Chris Angelico wrote: On Mon, Feb 18, 2019 at 3:26 AM ^Bart wrote: I need to do what I wrote in the subject but... I don't understand how could I fix my code... :\ When you want homework help, it is extremely useful to post the entire challenge you were given, not just a one-line summary. What are you actually expected to do? What are the restrictions? Also, are you aware that there is a separate email list "for folks who want to ask questions regarding how to learn computer programming with the Python language and its standard library."? (https://mail.python.org/mailman/listinfo/tutor) I suspect, from your last few posts, that you should not be taking particular challenges, but should instead go back to the basics of how Python works. Reread the earliest material in your course and make +1 As explained earlier, asking helpful people 'here' to complete the task for you helps no-one! - you haven't really learned, and are unlikely to have mastered techniques necessary to pursue employment or hobby-interests, in future - you've asked community-minded folk to give-up their time - your trainer is unlikely to be fooled for long... sure you truly understand what is going on. Try to piece together what a section of code is doing, step by step. Write down on a piece of paper what the variables are at each point in the program. Then, AFTER doing the work manually, run the code and see if you were right. +1 I recently audited a set of courses (last one yet to be released) on Coursera, out of U.Mich (Michigan, USA): Python 3 Programming Specialization (https://www.coursera.org/specializations/python-3-programming). I'm not recommending it particularly - it doesn't fit with my personal approach (which may say more about me!) NB Coursera uses a 'freemium' business model. In my context "audit" meant 'evaluation', but in Coursera-jargon it means $free. Paying for such a course adds invitations to participate in project work, (?)final exam, and one hopes, earn a certificate. The reason this course caught my attention (and which is relevant to you, per Chris' and Dennis' recent advice) is that the course revolves around an 'active textbook'. This intersperses learning material with mastery exercises, and pertinently, uses a 'widget' which steps through code, line-by-line, showing exactly what is happening to each variable. I was impressed! In 'the good old days', we used to talk about having a 'paper computer'. In appearance, this was almost exactly like the above - where we could 'see' exactly (what we thought) was happening inside the CPU. It was a testing/debugging tool before the first line of code hit the Python (or whichever) interpreter/compiler. (who says Test-driven Development is a "new" idea?). In short, it is an excellent tool for visualising learning! NB There is a Python Debugger tool which operates similarly, but the learning tool is illustrative in nature, cf diagnostic. Having mentioned U.Mich/Coursera, one of the most famous Python courses available over-the-Internet is Dr Chuck's "Python for Everyone". I'm not aware if he has upgraded those to use the same active textbook tool. That said, it is an enormously-popular avenue for exploring Python! -- Regards =dn -- https://mail.python.org/mailman/listinfo/python-list
Re: Sum of few numbers by using for and range
On Mon, Feb 18, 2019 at 6:12 AM DL Neil wrote: > > sure you truly understand what is going on. Try to piece together what > > a section of code is doing, step by step. Write down on a piece of > > paper what the variables are at each point in the program. Then, AFTER > > doing the work manually, run the code and see if you were right. > > +1 > > The reason this course caught my attention (and which is relevant to > you, per Chris' and Dennis' recent advice) is that the course revolves > around an 'active textbook'. This intersperses learning material with > mastery exercises, and pertinently, uses a 'widget' which steps through > code, line-by-line, showing exactly what is happening to each variable. > I was impressed! That sounds like an EXCELLENT way to do the second part - running the code to see if you were right. I would still recommend doing it 100% manually first, *writing down* your expectations, and only *then* letting the computer do it. It's easy to watch the computer do something and go "yes, of course that's what happens", but to still not be able to replicate it yourself. True comprehension means being able to predict what will happen. Consider it like a falsifiable hypothesis in scientific research. "I expect that, when I do X, Y, and Z, the result will be Q." Then you actually perform those steps, and see what the result is. Were you right? If not, how do you modify your expectations/hypothesis to correct it? It's the last step that is the most interesting, because that's where you truly learn. (And sometimes, that learning is expanding the corpus of human knowledge. It's only when you disprove your expectations that you can begin to pin down something like "oh so time flows at different rates depending on gravity" or "huh, so it turns out black-body radiation doesn't behave the way all the math said it would".) ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: Sum of few numbers by using for and range
On 18/02/19 8:32 AM, Chris Angelico wrote: On Mon, Feb 18, 2019 at 6:12 AM DL Neil wrote: The reason this course caught my attention (and which is relevant to you, per Chris' and Dennis' recent advice) is that the course revolves around an 'active textbook'. This intersperses learning material with mastery exercises, and pertinently, uses a 'widget' which steps through code, line-by-line, showing exactly what is happening to each variable. I was impressed! That sounds like an EXCELLENT way to do the second part - running the code to see if you were right. I would still recommend doing it 100% manually first, *writing down* your expectations, and only *then* letting the computer do it. It's easy to watch the computer do something and go "yes, of course that's what happens", but to still not be able to replicate it yourself. True comprehension means being able to predict what will happen. Consider it like a falsifiable hypothesis in scientific research. "I expect that, when I do X, Y, and Z, the result will be Q." Then you actually perform those steps, and see what the result is. Were you right? If not, how do you modify your expectations/hypothesis to correct it? It's the last step that is the most interesting, because that's where you truly learn. (And sometimes, that learning is expanding the corpus of human knowledge. It's only when you disprove your expectations that you can begin to pin down something like "oh so time flows at different rates depending on gravity" or "huh, so it turns out black-body radiation doesn't behave the way all the math said it would".) +1 For reference Chris (et al): The 'active textbook' offers 'windows' which seem to be Idle, but in a controlled and prescribed environment. So, the learner first writes his/her code, and only then can run and/or step-through, as described. +for ^Bart: IIRC the early stages of the U.Mich/Coursera Py3 Pgmg course included coverage of "accumulators", which concept you have yet to learn - and certainly lists and ranges appear. Thus dealing with both of the conceptual errors causing grief in the original code-snippet. All the best! -- Regards =dn -- https://mail.python.org/mailman/listinfo/python-list
Access control class?
I'm developing an application which benefits from access control. By searching the web I've found a couple of data-entry-with-password classes yet I've no idea how to evaluate them for security. I'm looking for advice from those of you who have experience with access control. Thanks in advance, Rich -- https://mail.python.org/mailman/listinfo/python-list
revisiting the "What am I running on?" question
having worked on some other things for a while i
didn't put much emphasis on working on this until i
had the other bugs taken care of.
so now back into it we can go... :)
what i came up with (sorry, i hate yet another not
invented here thing, but this is just where i ended up
after some pondering).
simply put. if i'm running on a computer and i
don't easily know why kind of computer how can i
answer this in a quick way without getting overly
complicated that also will cover most of the easy
cases?
i came up with this:
comments? additions? clarifications?
i don't have a windows system to test this on,
does it work?
thanks :)
=
import re
import tempfile
def sysprobe ():
sysprobetmp = tempfile.gettempdir()
print ("Temp directory : -->" + sysprobetmp + "<--\n")
result = re.search("^/(tmp)|(var)|(usr)|(opt)|(home)", sysprobetmp)
try:
print ("Result : -->" + result.group(0) + "<--\n")
return ("posix")
except:
pass
result = re.search("^[A-Za-z]:", sysprobetmp)
try:
print ("Result : -->" + result.group(0) + "<--\n")
return ("windows")
except:
pass
return ("unknown")
def main ():
print (sysprobe())
if __name__ == "__main__":
main()
=
on my system i get:
=
(env) me@ant(39)~/src/salsa/bits/sysprobe$ python3 sysprobe.py
Temp directory : -->/tmp<--
Result : -->/tmp<--
posix
=
songbird
--
https://mail.python.org/mailman/listinfo/python-list
Re: revisiting the "What am I running on?" question
songbird wrote:
...
> result = re.search("^/(tmp)|(var)|(usr)|(opt)|(home)", sysprobetmp)
i changed that line to:
result = re.search("^/((tmp)|(var)|(usr)|(opt)|(home))", sysprobetmp)
just to make sure the leading slash is not just grouped
with the first string. i like to be more explicit with
my precedence if i'm not sure what the language might
actually do... :)
songbird
--
https://mail.python.org/mailman/listinfo/python-list
Re: revisiting the "What am I running on?" question
On 2/17/19 8:46 PM, songbird wrote: simply put. if i'm running on a computer and i don't easily know why kind of computer how can i answer this in a quick way without getting overly complicated that also will cover most of the easy cases? i came up with this: comments? additions? clarifications? [...] (env) me@ant(39)~/src/salsa/bits/sysprobe$ python3 sysprobe.py Temp directory : -->/tmp<-- Result : -->/tmp<-- posix Python 3.7.2 (default, Jan 10 2019, 23:51:51) [GCC 8.2.1 20181127] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> sys.platform 'linux' -- https://mail.python.org/mailman/listinfo/python-list
Re: revisiting the "What am I running on?" question
On 2019-02-18 02:46, songbird wrote:
having worked on some other things for a while i
didn't put much emphasis on working on this until i
had the other bugs taken care of.
so now back into it we can go... :)
what i came up with (sorry, i hate yet another not
invented here thing, but this is just where i ended up
after some pondering).
simply put. if i'm running on a computer and i
don't easily know why kind of computer how can i
answer this in a quick way without getting overly
complicated that also will cover most of the easy
cases?
i came up with this:
comments? additions? clarifications?
i don't have a windows system to test this on,
does it work?
thanks :)
=
import re
import tempfile
def sysprobe ():
sysprobetmp = tempfile.gettempdir()
print ("Temp directory : -->" + sysprobetmp + "<--\n")
result = re.search("^/(tmp)|(var)|(usr)|(opt)|(home)", sysprobetmp)
try:
print ("Result : -->" + result.group(0) + "<--\n")
return ("posix")
except:
pass
result = re.search("^[A-Za-z]:", sysprobetmp)
try:
print ("Result : -->" + result.group(0) + "<--\n")
return ("windows")
except:
pass
Don't use a bare except, it'll catch _any_ exception.
If the regex matches, re.search will return a match object; if it
doesn't match, it'll return None.
In any case, +1 to Dan's answer.
[snip]
--
https://mail.python.org/mailman/listinfo/python-list
