« first day (1594 days earlier)      last day (3372 days later) » 

12:31 AM
I'm running Apache. I don't know much python yet, but need to send a value from a web page to I2C. I have a tkinter program to control it, but I need to control it from the web. Help/Ideas please?
 
1:11 AM
import subprocess
return subprocess.check_output(['git', 'rev-parse', 'HEAD'])
how would I run the above for a git repo at a particular path?
 
1:38 AM
cwd=repo
 
 
2 hours later…
3:39 AM
Hi Is there someone who could help me write a function in python?
Write a function called integer_from_user(smallest, largest), that satisfies the following specs:

- if either of the two arguments is not of type int, the function should return None.
- the function should ask the user to enter an integer between smallest and largest. To do that, you can use the following two lines:
print('please enter an integer between', smallest, 'and', largest, ':')
text = input()
- do not worry about what happens if the user does not enter an integer.
- as long as the user enters integers less than smallest or greater than largest, the function keeps asking the user t
while(True):
result = integer_from_user(20, 100)
print('you entered', result);
if (result == 50):
break

print("exiting")
 
user559633
this isn't a homework service
 
Well I am trying to learn python... Am not a student
been trying to do this since morning
but not able to figure it out
 
user559633
where is that question from then?
 
its from a self learning websute
website
 
user559633
which
 
user559633
3:44 AM
prove to me that it's not homework and i'll help you along
 
user559633
that's a link to a homework assignment..
 
it has all the lectures on this website
trying to learn
and do the programs together
if you know a better place to learn, please suggest
 
user559633
given as it's right in time for that homework assignment to be due (Assignment 5. Due date: Wed 02/25, 11:55pm.), this is suspiciously like homework
 
well then help me tomorrow
 
user559633
3:48 AM
okay. i can guide you now
 
user559633
what have you tried so far?
 
let me show you
def integer_from_user(smallest, largest):
    print('please enter an integer between', smallest, 'and', largest, ':')
    text = input()

    if (type(text) is not int):
        return None

    if enter_num >= 1 and enter_num <= 20:
        return result

while(True):
    result = integer_from_user(20, 100)
    print('you entered', result);
    if (result == 50):
        break

print("exiting")
 
user559633
press up, then highlight your code, and press control+k to format
 
user559633
what version of python?
 
3.3.2
 
user559633
3:52 AM
cool, give me a second
 
okay
 
user559633
what kind of input do you believe to be coming from input()?
 
right now its taking all inputs
but it should be able to filter out between strings and variable
 
user559633
sure, but you're checking ` if (type(text) is not int):`
 
if its not int is should return none
 
user559633
3:55 AM
So you believe the text var to be what type?
 
integer
 
user559633
What does the documentation say is returned by input?
 
0?
 
user559633
Where do you see 0?
 
3:57 AM
in the link you sent lol
 
user559633
If the prompt argument is present, it is written to standard output without a trailing newline. The function then reads a line from input, converts it to a string (stripping a trailing newline), and returns that. When EOF is read, EOFError is raised.
 
user559633
What would you expect text to be?
 
Lol I didnt understand anything in that tristan
 
user559633
What part?
 
user559633
" The function then reads a line from input, converts it to a string"
 
3:58 AM
If the prompt argument is present, it is written to standard output without a trailing newline. The function then reads a line from input, converts it to a string (stripping a trailing newline), and returns that. When EOF is read, EOFError is raised.
The thing is my friends study at UTA and I had this interest in learning programming... I started with some online sites but didnt work
and they told me to learn it from their site
since its all online
but since i don't have anyone to teach
 
user559633
I think you need to read the documentation more before trying this sort of problem.
 
now i feeling lost
 
user559633
If the documentation I sent you is making you feel lost, it will help you to start at the beginning.
 
can you suggest me a good site to learn python instead? like that could start from real basic and easy to understanf
 
user559633
But don't worry! start here docs.python.org/3/tutorial/index.html
 
4:01 AM
understand*
 
perfect let me try learning from here
 
user559633
Take your time and don't rush
 
Lol trying... but people say python is just the basic
i wonder whats coming next
 
user559633
If you run into something and you're like "hey, this doesn't make sense," then re-read it a few times, search a bit, then ask in here if it's still not making sense
 
user559633
4:02 AM
Python is a really powerful programming language.
 
btw is it a good idea to start with python?
 
user559633
Most people that think Python is only good for basic tasks aren't very good at using it.
 
or should i start with something else?
 
user559633
As a first programming language? Definitely.
 
user559633
It has a nice soft learning curve and is extremely flexible and powerful.
 
4:03 AM
:)
 
user559633
I typically write in Python and then only move to something compiled if Python can't do it fast enough. So far, I've never really had to switch to a different language.
 
I been doing it correct all these days. this one program spinned by head off
like the second program, I did that in 2 mins
so python it is
 
user559633
To give you a little bit of insight, in:

`text = input()`

the `text` var is a string.
 
user559633
Your program has some other major errors after that, so it's really in your best interest to take your time with the tutorial
 
yes coz the question says you have to accept all inputs
and if the input is a string it should return none
 
user559633
4:06 AM
Yes, but all input is of string type :)
 
user559633
Put that code you wrote aside and come back to it after spending a couple weeks with the tutorial.
 
if its an integer and between 20 and 100 it should say say you choose 20 or 21 or whatever the input was
 
user559633
Again, check out the tutorial. You're not writing the logic you think you are in that program.
 
yeah am gonna start again on python's website
 
user559633
good luck!
 
4:08 AM
thanks tristan
 
user559633
no problem at all Bhavin
 
:)
hey tristan btw is this the latest version of python am working on?
 
user559633
you could switch to 3.4, but for your purposes, that's a fine version :)
 
whats the difference between them?
 
user559633
lots of stuff that doesn't matter to you just yet
 
4:11 AM
okay
 
4:48 AM
sup
anyone here?
i need urgent help
anyone?
 
5:37 AM
you don't since you didn't ask your question
@tristan there are better error messages in 3.4 :D
@Player72 sopython.com/chatroom part on "Asking a question" :D
 
hey,.. im stuck with a tastypie issue....
i have three models which need to be created with one post call...how do i do it with resources??
 
hem, in rest one usually does not create 3 resources when creating 1
I do not know, I do not knwo tastypie
 
hmm...ok!!...so how do you do it with rest...create 3 diff api routes??
 
5:53 AM
no since I do not do rest :d
nor django
but you can always create an ordinary django view for that?
 
yup...i can...i was just wondering if i could use tastypie to do that??
 
that I cannot answer myself
 
thats ok...thanks aneways!
 
 
1 hour later…
7:14 AM
Cbg
 
Cbg
 
@thefourtheye even on python 3 the stdout shouldn't buffer if it is connected to a terminal (that is the terminal ought to decide)
 
8:10 AM
@AnttiHaapala I am still researching and going through the code.
In 3.x, line buffering is activated by default
 
I can only trigger this behaviour with python zzz.py|cat on linux
 
So, if we don't print a new line character, it is supposed to buffer...
I am not actually able to reproduce that...
That is where I am stuck :'(
 
the terminal should cause that if python recognizes it, it then sets the file to unbuffered/linebuffered
but I think op said something about that being embedded so maybe stdout is not a real file
 
mmmm, I assuming its stdout as he hasn't explicitly mentioned about the actual file object used,
Can you please try this?
for i in range(10):
...     print(i, end='')
...     time.sleep(1)
...
...
In your 3.x terminal?
It is supposed to print only at the end
In my machine, the buffering is not happening :(
 
neither on mine
he said it is an embedded interpreter for some program x
so it is sys.stdout, but the sys.stdout is not a terminal.
 
8:15 AM
mmmm, but I am still not satisfied with my digging :(
 
this is also unable to reproduce
it is not a problem on python, but on another program :D
and OP didnt even say what is that program
 
But, the program I gave above should have blocked the output... Why didn't it block?
It means either my understanding of line buffering is wrong or something else is happening in print
 
0
Q: How to check text file is not empty in python

user3573959I wrote a script to read text file in python. Here is the code. parser = argparse.ArgumentParser(description='script') parser.add_argument('-in', required=True, help='input file', type=argparse.FileType('r')) parser.add_argument('-out', required=True, help='outputfile', type=argparse.Fi...

actually unable to reproduce this either
should be closed
 
CVed
 
Yes, if you want to test an instance of a class, you usually need to create one to have an instance to test. — Antti Haapala 50 secs ago
 
8:26 AM
Cabbage
 
what's this?
Thanks for contributing! Have more to say?
answer similar questions
Then ask your friend about how it was deployed and tell us, otherwise this is a bit difficult. — Antti Haapala 12 secs ago
it was deployed by my friend, but I can't contact him. — Filo Limantara 1 min ago
 
8:47 AM
@AnttiHaapala Phew.... I just confirmed that what you said is correct.
> the terminal should cause that if python recognizes it, it then sets the file to unbuffered/linebuffered
Yes, if the environment is a terminal then the buffering defaults to line buffering which is the same as disabling buffering it seems
 
well it is not the same :D
print(i, end='') does not display on my computer immediately
 
What?!?! In Terminal?
 
yes
bc it is linebuffered
there is no endl
 
>>> print(1, end='')
1>>>
I get it immediately
 
>>> for i in range(10):
...     print(i, end='')
...     time.sleep(1)
...
0123456789>>>
tihs i mean
sorry for being unclear
 
8:50 AM
This prints individual digits immediately, right?
Awesome, I spent the last two hours for nothing
I was using a program called bpython3, which is not the same as python3 interpreter
 
does not print immediately
10 seconds between ... and 0123456789>>>
python flushes the stdout before prompt though
 
Sigh.... I should never use bpython
I updated my answer. Can you please check once. Will this qualify as an internals question?
 
bc there are issues that:
unix terminals are line buffered
>>> import time
>>> for i in range (10):
... print i,
... time.sleep(1)
...
0 1 2 3 4 5 6 7 8 9
this buffers equally on Python 2
 
You would probably need some sort of curses thingy to do what you want
 
@thefourtheye anw, I couldn't find any difference in observed behaviour between python 2 and 3, though it does not mean that there is none
 
9:03 AM
Yup, I updated the answer,
Probably the line buffering is specific to all the terminals.
Hope the answer is clear now.
Okay I modified the answer to show that line buffering is something which is common across the terminals.
Its close to 3, rbrb for lunch...
 
9:19 AM
cabbage
 
9:33 AM
I love Kickstarter, but you could lose money so easily...
 
Oh, Eternity will be out soon!
That's the only thing I've backed
 
I've backed two things, and both seem to be on progress and due to arrive soon.
 
cbg
 
would inheriting from file be a good idea? I am calling a subprocess via Popen and I want it to write everything to stdout and stderr as usually, but at the same time I would like to fetch this output so I can process it. I am thinking about writing a class that inherits from file, send its instance to popen as stdout, and override write method to write both to stdout and string (or StringStream). Does it make sense to you?
 
@Nebril no, never, there is no such thing as file in Python (3 especailly)
 
I am on 2.6
 
You should upgrade to 2.7 (at least) if you can.
 
@Ffisegydd Already backing up. Played the demo then backed for $50
Ooops
 
I know I should ;)
I really can't right now
 
9:45 AM
I'll try the demo later (didn't realise there was one)
Ah it's Greenlit. Excellent.
 
9:56 AM
 
@Ffisegydd that does look quite cool
Backed.
 
@Ffisegydd shouldn't the last one for HV's be showing an SO question?
 
10:20 AM
I've set that kickstarter to remind me 48 hours before it finishes. Will see how it's doing and decide on whether to fund or not.
 
office cbg
 
@Martijn your office is offering cbg!? How cool is that... our influence spreads.... rubs paws together - muahhahaha muhahahah
 
@JonClements nope, but there's someone here backing the most delicious cakes. He'll give me advance notice if lemons are involved, even.
3-4 times a week there'll be something new.
 
@Martin I actually watched the great british bake off last night - only because it had David Mitchell... he was hilarious
 
Gonna watch that on Friday. I do like GBBO.
 
10:45 AM
@JonClements My family will watch that sometime today, I think.
 
@JonClements sounds awesome. My wife is obsessed with that programme.
 
@RobertGrant I don't watch it... but it had David Mitchell in it! So it got watched...
I'm such a Mitchell fan-boi
 
Yeah, I like the fact he's funny mostly because he has an amazing vocabulary
 
@JonClements: :-P
 
@JonClements: yay, lets go find some more ultra-advanced one-liners! :-P — Martijn Pieters 1 min ago
@Martijn hehe... sorry... couldn't resist :)
(but it'd work at least! - and doesn't require sized containers :p)
 
11:00 AM
You're not using significant whitespace, as far as I can see
 
@Bhavin could you put it on dpaste/gist and explain what you're trying to do before posting a massive codeblock in the room please?
 
I am working on a program and its a combination of 2 python programs. they are working fine individually but when I try to combine them something goes wrong and only one program works and the other half doesnt.
Am trying to see if someone in the room can help
Sorry about the code... New to coding and programming... didnt knew how to paste it
 
@Bhavin Define doesn't work.
Give us a real problem description; input given, output expected, errors you got instead (or unexpected output).
 
@Bhavin go to dpaste.com or similar - it's easier to have text than images...
@Martijn hardly "ultra-advanced" btw
 
@JonClements compared to the level the OP is at?
 
11:06 AM
@JonClements: what should i select in syntax on dpaste?
 
@Bhavin at a wild guess... Python ?
 
@Martijn interesting... it appears random.choice on an empty sequence throws ValueError and while that occurs an IndexError...
@Bhavin reminds me of a euler project task
 
@JonClements This program has to get an input say "123"... add the input "1+2+3" and for the result "6" it should determine if its prime or not
 
@Bhavin looks like you're trying to do too much in one place
 
11:12 AM
@jon
@JonClements new to programming. I wonder how you guys survive coding and programming
 
@Bhavin not sure we do :p
 
@JonClements been trying this one program since 11 pm and its 5.15 am lol
 
Okay, well, you've made an attempt - what are you doing it for? Looks like a school assignment or something...
 
@JonClements learning programming. My daughter goes to school. I always wanted to learn programming so been trying to do everything she does.
 
Okay, break this up def prime_digit_sum(number)
 
11:17 AM
Hello?
 
@imanedergal welcome
 
Thank you ^^
 
oh ffs, it's back to 8 spaces again
 
@Bhavin this may help: learnpythonthehardway.org
 
I have a little question about dictionnaries , let me know when you guys are free!
 
11:19 AM
You can buy the book or just do it online free
 
@imanedergal Just ask :)
 
@imanedergal sure... just ask....
 
@imanedergal best to ask and not expect an immediate response
 
def sum_of_digits(text):
    return sum(int(ch) for ch in text)
Ahh, that's better
 
Okay, it's my first time. Didn't know how it works. Anyway, so! I need to add items to my multi-dimensionnal dict , but the items are in variables.
so it's something like this:
ConsomRatio: { "to_produce": {"ingred":"ratio", "ingred":"ratio",...}
{ "to_produce": {"ingred":"ratio", "ingred":"ratio",...}
 
11:22 AM
nvm
 
But I need the values of the variables, not their names!
I import the items from an Excel sheet, with a "for". That is why they have the same name...
 
Bah, my bad team, should have noticed that @Bhavin has already asked here
 
@Jon tried still not working
Yeah I tried posting there too
 
@Bhavin we don't allow newly posted question (see sopython.com/chatroom) in the room - that's what the main site is for, so you'll have to sit back and be patient for an answer... it's less than an hour old
 
Out of interest, why do you have two separate accounts?
 
11:30 AM
@JonClements: Sorry I didnt knew that. I just love efficiency. It you could get a solution thats quicker, why not? :)
if*
 
@Bhavin because the main site is the place to ask questions and have them answered - the chat system is for discussing questions, how you could make them clearer etc... not asking the same question that people frequenting the tag will already have seen
 
Incidentally, that answer you got on your question is pretty slightly awful.
 
cbg
 
@JonClements apologies
 
@Ffisegydd Some of the code is a bit dubious, like theif number in (0,1,-1):, but that's nothing compared to some of the stuff he says in the explanation, eg The math.sqrt function returns the square of a number and The (int(x) for x in text) is called a generator comprehension
 
11:42 AM
Lol
 
Oh, and the code uses an un-named except.
 
re-cbg
 
@Ffisegydd @PM2Ring For a newbie like me, it's pretty awesome to see a program work. I got to go work in 2 hours and I been awake all night to make this one program work. Wish I would have studied programs rather than business while I was in school.
 
12:00 PM
@Bhavin lol... never took a programming course in my life :)
 
@Bhavin and it shows. Don't be like him.
 
@Robert sound advice? :p
 
:)
@Bhavin I'm joking, be like him and not like me, who did take courses and wishes he knew as much Python as anyone else here
 
@Bhavin Hey, even after decades of programming in a variety of languages I still get a buzz from seeing my programs do what they're supposed to do. Even simple ones. :)
 
@Bhavin - I'm the same. That's why I do it for a living ;)
 
12:15 PM
@all you guys are amazing
 
@PM2Ring the scariest thing is when it seems to work first time
 
@Bhavin: If you want to see no_name's modified code in un-scrambled form, just click on the answer's edit link. I guess someone ought to put his code back into a code block, since he seems to have disappeared...
 
@RobertGrant I'll never debug a bit of code more than code that works first time
 
I definitely prefer testing by deliberately breaking every step of the way
 
@JonClements: In Python 2 you get an IndexError.
Python 3 catches that and gives you a more helpful ValueError instead.
The underlying IndexError is then still chained.
 
12:16 PM
@RobertGrant That's a major thing I love about Python - running properly first time seems to happen much more often than in other languages. :)
 
@PM
Lol Sorry
 
Yeah I would say that I like languages like Python that fail loudly if you give them the wrong thing. I think maybe that's a feature of terser languages in general
 
@Martijn that explains why I don't recall seeing it in 2.x then :)
 
@PM2Ring: his program works fine except when I enter an non integer it gives me a bunch of errors.
 
actually, it's slightly different.
But the principles are the same..
The Python 3 random.choice() was refactored a bit.
so it doesn't use int(self.random() * len(seq)) and uses self._randbelow(len(seq)) instead.
 
12:20 PM
Is there a simple way to learn programming I wonder
 
to get an index into the sequence
@Bhavin there is no silver bullet.
 
@Bhavin check the link I showed you
 
You just keep at it.
 
@Bhavin Yeah. There are a few flaws in his code. Eg, it'll raise a ValueError: math domain error if you feed it a number < -1. But it should work ok if you feed it proper input.
 
@RobertGrant The hard way lol
 
12:22 PM
I wouldn't say programming is hard - it just depends on your mind set and what you're trying to achieve
 
Programming is fun!
 
Give me a sec, and I'll put his code back into a code block. I'm tempted to fix up some of the flaws, but I'm feeling too lazy tonight. :)
 
@PM2Ring Those red errors are now a part of my everyday life. Am trying to get rid of them but they seem to enjoy my company
 
@Bhavin it sort of is the hard way, but just look. It's really good.
@Bhavin doesn't assume any prior knowledge
 
@Robert yeah, but when you look at the number of LPTHW questions on the site... sighs
I can't even work out why the heck Zed is trying to introduce some of those principals
 
12:24 PM
@RobertGrant thank you. I will start working on it as soon as am done with this program
 
I didn't fix no_name's code, but I did fix some of the spelling mistakes & errors in the explanation. :)
 
@PM2Ring I tried his program in a different way. Is it okay to post it there?
 
Yo shouldn't post a new question as an answer, of that's what you mean.
 
Thou even my program is giving me those same errors when I input -1
 
@JonClements Same here. LPTHW has a lot of fans, but I must admit I'm not totally impressed with it.
 
12:30 PM
Any suggestions on what should I do about these non integer inputs
 
@Bhavin I guess you mean that you've tried to improve no_name's code but it's still not quite doing what you want.
 
Umm.... maybe time for "Learn Python the sopython Way"? :p
 
@PM2Ring: Can't use the work improve. You guys are experts in this. But yes its not doing what I want it to do. Its still giving me an error when a negative number is fed
 
cbg
 
12:34 PM
@JonClements that's a good idea
 
I tried adding this little thing but its still giving error

if (type(number) is not int):
return None
 
Or the more mystic "Learn the Sopython Way"
 
Use isinstance(number, int) to test of something is integer or not.
 
@Bhavin non-integer inputs?
as in foo = input()
 
bah, one of the advantages of working from a home-office is that you don't have to really go anywhere
(except for meetings)
 
12:37 PM
I like the idea of writing the official sopython's Python guide/tutorial. Not a rewarding task though.
 
but you have to make and pay for your own lunch
 
@MartijnPieters does _randbelow behave well or is it biased?
 
(mind you - with the amount of garlic and clove leave I've put in this spagetti bolognese - probably best I'm not in an office)
 
the first rule about amount of garlic is that there is no such thing as "too much" :D
 
@AnttiHaapala We're talking about this slightly dodgy piece of work: stackoverflow.com/a/28740528/4014959
 
12:41 PM
@AnttiHaapala killing vampires at 10 paces isn't far from the truth right now :)
 
could use some more garlic :D
 
There are also a few odd things in the explanation to that code, but I just fixed most of them.
 
@PM2Ring the is_prime must be the most awful I've ever seen
 
@PM2Ring Lol did you delete his whole reply?
 
I'm feeling slightly disorientated - we just had a short power failure. But my hard drive appears to be fine.
@Bhavin No, I just fixed it up a little bit. You might need to refresh the page in your browser (but you shouldn't have to). Also, you can see earlier versions of his answer if you click on the blue "edited 20 mins ago" text at the bottom of his anwer above my avatar.
@AnttiHaapala The if num in (0,1,-1):is classic.
 
12:47 PM
yes
 
@Ffisegydd how'd your Irish stew recipe work out?
 
It was Italian and it was lovely.
 
deleted?
 
Guess its gone... Cant see it anymore
 
@Bhavin Don't do that. His while loop will only accept integer input. You can add an if statement to it so that it will only accept non-negative integers. There are a couple of different ways to do that.
@Bhavin Hey, you're right! It was there a minute ago...
 
12:53 PM
Self-deleted by author.
Do you guys want me to copy+paste the content out?
 
If that's a good code, why not :) @Ffisegydd
 
Thanks
 
user559633
@AnttiHaapala yeah, there's better error messages, but it's not really that more helpful at the level of understanding built in types.
 
user559633
@Bhavin how's that tutorial doing?
 
12:58 PM
@tristan less unicode errors
 
@tristan: trying hard
 
@Bhavin As you may guess from some of our comments, it's not ideal. But it's a reasonable base to work from.
 
user559633
@Bhavin what page are you on? did you stop reading it and return to trying to write programs?
 
@Bhavin you can edit messages by pressing the up arrow, rather than typing a new one.
 
Eh, somehow doing a git fetch made Firefox freeze.
My Internet pipes must be congested.
 

« first day (1594 days earlier)      last day (3372 days later) »