« first day (2387 days earlier)      last day (2554 days later) » 

12:40 AM
Folks, I'm looking at Python Scientific Distributions: Anaconda, Python(x,y), WinPython. Which one is the preferred one?
 
1:34 AM
How to set env variables through python where those env variables are stored in a py file?
 
Recbg
@AvinashRaj just import <filename> now they are actual python variables
 
Ya,, but we can reference those variable only with settings.variablename, right?
But I want to do os.environ['variablename']
 
1:56 AM
@AvinashRaj why?
 
Because I want to export some variables (ie, set sys variables) before running the app locally.
so that it would get the local settings..
 
What do you mean by "export variables"?
 
ie, i want to set some system variables (linux)
 
This sounds like a proposed solution to another problem. What is the original problem that you are trying to solve?
You said you want to do os.environ['variablename'] but if you already have the variables set in a .py file there is no need to do this. When I ask why you want to do it this way, your answer is basically just "because I want to" which is not very informative.
If you want the user to override the value of a variable from settings.py with an environment variable, then in settings.py just do variablename = os.environ['variablename']. Then import settings in your program and do settings.variablename as usual.
 
 
5 hours later…
7:17 AM
@WayneWerner Actual processes, aka it calls fork() somewhere deep down. I think the parent process doesn't terminate and a few of the children don't terminate. Am I supposed to write some wrapper code so that exceptions kill all the children and parent process?
 
 
1 hour later…
8:58 AM
Cabbage
 
9:11 AM
cbg
 
@AvinashRaj I don't know what Windows does, but on a POSIX system a process can only affect the copy of the environment vars that it inherits and which it passes to its child processes, it cannot affect the environment vars of its parent process. So your Python program can modify os.environ and any processes it launches (eg via subprocess) will get that modified os.environ.
But (AFAIK) you can't run a Python script that modifies the environment vars of the shell its running in so that subsequent programs run in that shell see your modified vars. And even if you want to do it with a Bash script that uses the export built-in you need to source the script so that it runs directly in the current process.
 
10:00 AM
Surely we have a decent dupe target for this? The for loop modifies t_list and appends it to transposed, and the OP is surprised that all the sublists in transposed are identical.
I don't want to hammer it with List of lists changes reflected across sublists unexpectedly because the OP isn't using multiplication to replicate the sublist.
 
Hello guys, I've a query on event binding in python tkinter can some one help me out
0
Q: Query on Python tkinter bind event

SundararajanFriends, I'm trying to make hover effect in python(3.5.2) on a button, I use the below code. from tkinter import * root = Tk() root.geometry("200x200+400+400") myBtn = Button(root, text="TEST") myBtn.pack(padx=10, pady=10) myBtn.bind("<Enter>", lambda event, h=myBtn: h.configure(bg="red")) myB...

 
Hi @Sundararajan We normally ask people to wait a day or two before asking for help with their SO questions. Please see the room rules
My guess is that your OS's window manager is imposing its own hover style and overriding what Tkinter suggests. See what happens if you do
myBtn.bind("<Enter>", lambda event, h=myBtn: h.configure(bg="red"))
myBtn.bind("<Leave>", lambda event, h=myBtn: h.configure(fg="yellow"))
When you hover, you'll get the window manager's default change, but when you leave you'll see that both the fg & bg colours have changed.
 
10:22 AM
@PM2Ring OOPS sorry, I didn't knew it
yes, you were right, I'm using linux lite and it have a default hover effect it seems.
but when i leave it give both the effects like you said
Is there any workaround or suggestions to override the default effect?
Thanks for helping me out
@PM2Ring Sprouts
 
@Sundararajan There might be a way around this. I'm trying a few options. Unfortunately the Tkinter docs at effbot haven't been available for the last day or so: it looks like they're having server troubles.
 
yes, effbot was down.
No problem get back to me when you got some clue on this.
Melon
 
10:39 AM
Hi, I am using python for the first time on windows, trying to build a web scraper. I executed "pip install bs4" in cmd, then wrote "from bs4 import BeautifulSoup as soup" in a .py file, but executing it in SublimeText gives me Unexpected identifier: bs4

Whats going wrong?
 
@Sundararajan Here you go.
myBtn.bind("<Enter>", lambda event, h=myBtn: h.configure(activebackground="red"))
myBtn.bind("<Leave>", lambda event, h=myBtn: h.configure(background="yellow"))
I suppose I ought to submit that as a proper answer. :)
 
Wow, It worked like a charm
Melon
@PM2Ring Yes, Go ahead.
:-)
 
I explain more about the evils of "star" imports here
@Sundararajan Done.
 
10:55 AM
sure will read them. I heard its not a good practice to use * when importing but I can't help it :)
but will change my habit for sure :)
 
Sure you can :P
cbg
@Phil I can only help with a trivial question: did pip install succeed and did you use the same version of python than for which you installed bs4?
I dislike custom errors of editors
 
@AndrasDeak I assume the error is from wrong built configuration as I see something with node and npm in the error log. I am switching to intellij and making a python project
 
11:17 AM
OK, I don't know what any of that means:) Hopefully others can help.
 
 
3 hours later…
DSM
2:08 PM
@NickAlexeev: I wasn't around at the time to see the question, but I think the conda ecosystem (including Anaconda) is the best option, and the one where more of the Python science coding guys are active at the moment.
 
2:27 PM
recbg
 
3:15 PM
!head file.txt

Anyone know what the !head command in jupyter notebook does? I played around with it and it seems to just print the text of a text file?
 
DSM
head prints the first few rows of a text file. Compare tail, which prints the last few.
 
@moondra No idea, but head is a standard Unix program. It prints the beginning of a text file, by default the first 10 lines, but you can modify that by giving it an -n optional argument.
 
DSM
@PM2Ring: the ! just escapes the interpreter and executes the command in the shell.
 
Ah, right.
 
Ah, I see. Thank you. So to modify it, I would write !head - 15 file.txt ?
EDIT: It seems to be working. =)
 
3:27 PM
yup
 
@moondra That should be head -n 15 file.txt, but GNU head accepts the old head -15 file.txt form too. You should take a look at the man or info pages. Or at least head --help.
 
Or head --lines=15 for explicit:P Although that again might be a GNUism
 
 
1 hour later…
5:29 PM
Cbg
Passed my Technician class ham radio license exam this morning. And after only 2 hours of sleep last night, too.
 
Ham radio license?
 
AKA Amateur Radio.
 
good job
 
In the US there are three levels. The first one is pretty easy if you already understand basic circuits stuff
Like resistance, capacitance, etc
There are questions about regulation, too, but the test ID multiple choice, so it is not difficult to eliminate wrong answers
A friend loaned be a hand held radio until I get my own
 
DSM
Pineapples for CA. What was the drive? (Behind getting the license, I mean.)
 
5:46 PM
Nothing more. I have been interested for several years now. Finally met someone who was getting license, too, and had information about local examiners. That gave me the little push I needed to do it.
I recently learned about software defined radio, too. I want to get some equipment and deliver into that in the next year or so.
s/deliver/delve/
 
Ell
6:07 PM
Hi folks
Is anybody here familiar with numpy? I'm having an issue with indexing
specifically, I'm not sure how to decipher: [:200, 300:340]
 
@Code-Apprentice It may not be the best, but some of the equipment is dirt cheap. For example: nooelec.com/store/sdr/sdr-receivers/…
 
@JerryCoffin bookmarked. Thanks for the link
Looks like a good way to start
 
hi guys. how do I extract Bla1 and Bla2 from "Bla1"<br>"Bla2" (content of an html-tag)? I have no idea how to reference the " as regular expression
 
@Ell :200 is the same as 0:200 which is the first 200 elements... probably rows. Guessing based on general python knowledge, not specific experience with that syntax not with numpy
300:340 is a slice from index 300 up to, but not including, index 340
@Phil have you tried a literal double quote?
 
you mean as escape character?
 
Ell
6:19 PM
@Code-Apprentice hmm. this probably means a 200x40 rectangle of the top left of an image then
ah no
200x40 somewhere in the middle
yes that's it :D
thanks :)
 
@Code-Apprentice Sure--there's quite a few more on that order as well.
 
@Ell middle left
@Phil no, I mean "
 
cbg all
 
Oh... Is the regex in a python string?
Use single quotes for the string or escape the double quote with \
@JerryCoffin are you a ham?
@JerryCoffin is that just a receiver? Or is it a transceiver?
I will have to get a Raspberry Pi to go with it
 
Suuuuure, we'll build a solver for a puzzle with no rules included: stackoverflow.com/questions/43699138/picross-3d-solver
 
6:41 PM
@Code-Apprentice That's just a receiver.
@Code-Apprentice No. I was once, but my license expired decades ago.
@Code-Apprentice Not particularly. It works fine with Linux or Windows.
 
I understand. Just a reason to get a pi
 
@Code-Apprentice Oh, sorry. For your SO: yes, @Code-Apprentice absolutely needs an R-pi. It is an absolute necessity.
 
6:59 PM
@MartijnPieters 3d nonogram, neat
 
@AndrasDeak you want to code up a solver in Python then? :-D
(presumably that is what they are asking about)
 
oh suuuure, I was going to reopen-vote :PPP
 
Also it's unclear how the rules of the puzzle extend to cover a 3d cube (if it is meant to be a cube).
 
yup, definitely a cube
 
(I've coded a nonogram solver in Python before, for pythonchallenge.com)
 
7:02 PM
and the lines probably indicate the direction; and each row of numbers corresponds to 4 lines along 4 neighbouring sides
topologically speaking, the hints are provided for rings
at least that would be my guess
 
All my cv-plses are lovingly handcrafted, so sometimes the product differs from the advertised picture slightly.
 
DSM-safe choice of words
 
For some reason, the hyphenation "DSM-safe" flips the context switch in my brain between room denizen and shrink manual.
 
> every time an image of code is uploaded a kitten somewhere dies.
I do not even understand why someone would even think to take a screenshot of code when copy paste is so much easier
 
7:25 PM
flicks through DSM … turns out it's called Integrated Development Environment Disorder. If left untreated, your brain eventually turns gooey and you completely forget how to operate a CLI.
 
I somewhat understand screenshots of a cmd window. Copy and paste there is far from intuitive. And none of the standard shortcuts work.
 
So it's not pronounced jooey? ;)
 
Context?
 
9 mins ago, by Zero Piraeus
flicks through DSM … turns out it's called Integrated Development Environment Disorder. If left untreated, your brain eventually turns gooey and you completely forget how to operate a CLI.
subtle pun warning
 
@AndrasDeak That pronunciation switch is enabled with [Alt]+[Right], I believe.
 
7:35 PM
always with the politics
 
Always and forever :-)
 
@AndrasDeak I understand the GUY reference but entirely miss the connection to the quoted passage
Okay, this screenshot probably has a reasonable excuse
 
I've been having a little bit of a scope quandary. I have a module from which I'm importing *. It has a bunch of functions and a few global variables. The problem is that if I change the value of one of those global variables in one of the functions, the change does not apply in the file that is importing the module. Any ideas?
 
@Code-Apprentice It's not an MCVE unless you courier the calculator to me.
@GiantCowFilms A guess … you're doing something like
from x import * # imports FOO and others
FOO = 'bar'
… which just rebinds FOO in the current scope.
Instead:
import x
x.FOO = 'bar'
 
7:51 PM
@GiantCowFilms mcve plz
 
@ZeroPiraeus more like
for x import *
print(FOO)
where FOO has been modified by a function originally from x, that was imported via *
 
@GiantCowFilms better yet, get rid of the globes and use return instead
 
@Code-Apprentice ?
 
Often globals are a sign that you are doing something wrong
They are very error prone
 
I don't see any other good way to handle this
I hate the fact that the functions are stuffed into modules
I just want to treat them like they are in the same file
 
7:54 PM
Can't I expect 27**-3 to be 3? because 27 to power of 1/3 is 3, where ** is exponent operator
 
a^(-3) is 1/(a^3), not a^(1/3)
 
@GiantCowFilms With the caveat thay you are suppoosed to show us a Minimal, Complete, and Verifiable example so that we aren't guessing in the dark, are you doing something like this?
# a.py

from b import *

print('imported:', FOO)
print('function:', get_foo())
set_foo('after')
print('imported:', FOO)
print('function:', get_foo())

# b.py

FOO = 'before'

def set_foo(arg):
    global FOO
    print('Changing FOO from %r to %r' % (FOO, arg))
    FOO = arg

def get_foo():
    return FOO
Oops, that's more pasted code than it felt like in my editor.
Result:
$ python3 a.py
imported: before
function: before
Changing FOO from 'before' to 'after'
imported: before
function: after
If so, you just Can't Do That. from x import y (or *; the mechanism is the same) gets the object bound to the name y in module x and binds it to the name y in the current scope. If something then rebinds a different object to x.y, your local y doesn't magically notice and rebind itself to match.
 
8:18 PM
((((you could always use a mutable object))))
embrace namespaces, they're one honking great idea
 
At this point it's probably time to link Facts and myths about Python names and values.
Yep, @Andras is right, the solution is to get over your dislike of namespaces and train yourself to avoid star imports. If you fight Python, it'll win. If you work with it, you'll both win.
 
@GiantCowFilms why can't you put all your functions in one file?
 
s/ask/all/ FTFY
 
That's what I said
@GiantCowFilms or better yet, learn how to use modules correctly
 
8:52 PM
@Code-Apprentice because they need to be reused across files
 
9:11 PM
Time zones are indeed difficult. It took me more than a month to realize that we're no longer in CET and no longer UTC+1.
Can we please stop renaming our time zones every equinox?
 
10:03 PM
I am defining a variable like so:
startrow = int(self.startrow.get().strip()) # 27

Then I run a function, in which changes the startrow value:

#in the function
global startrow
startrow = 3
but when I then leaves the function again, and prints startrow
It prints 27 for some reason.
Does a global variable (defined in a function) not overwrite a local variable?
 
10:32 PM
@SebastianNielsen Don't expect any meaningful responses until you put together a runnable, short, complete example (you know the drill) that produces your problem so that we can discuss it efficiently.
The behaviour you're describing sounds a bit surprising, which leads me to believe that if we start discussing this we'll realize that your problem is actually hidden in something you didn't explain clearly enough. We've done that enough times. Your starting point should be a proper MCVE by now.
 
 
1 hour later…
11:34 PM
@SebastianNielsen you are getting closer to enough information that we can help. I suggest using a service like pastebin or gist to provide example coffee which anyone can copy and paste and then run to get the exact behavior you ate adding about.
I also suggest that you try using a parameter and a return value instead of a global
 
your spell check/swipe/predictive text hates you
also: I told him as much
 

« first day (2387 days earlier)      last day (2554 days later) »