« first day (3270 days earlier)      last day (1683 days later) » 

12:01 AM
@AndrasDeak Thank you for the confirmation!
 
12:34 AM
@AndrasDeak No Andras, the OP is not clear. Users like that often only want to change the formatting, not string-replace the actual cell contents. We see this very often in pandas users. pandas actually has per-column formatters, also Styling. And if the user is using pandas under Jupyter, there's another layer too...
...Asking about formatting/visual styling in pandas is analogous to in base Python, beginner users often get obsessed with inexactness in floating-point numbers, but really they just want to control the output format, usually to '%.2f' or whatever.
...There is an excellent target answer on this somewhere on SO, but I can't find it right now to cite here. Most pandas users are unaware that DataFrame allows them to define custom formatters on a per-column basis.
 
 
1 hour later…
1:43 AM
@wim the SO search box doesn't alow us to filter out by min or max rep of asked, or whether e.g. that user's questions have accepted answers. That's the sort of extrat filter I'd apply. What about the rest of you?
cbg
Here's a problematic question, which at first glance sounds like it should be reusable, but turns out to be 2.x hacks involving ast.literal_eval Read data from CSV file and transform from string to correct data-type, including a list-of-integer column ... what to do with it? can it be made current and generic? ( I think not)
...because I needed a dupe target for Python - Adding 2 column CSV together without use pandas. Really the issue is simply that builtin csv package reads in everything as string, so you need to convert each input col to desired type.
...gives me a headache. Logging off.
 
2:07 AM
cbg
 
Is it possible to assign the same tensor to multiple slices (e.g. windows) of a larger tensor in PyTorch?
 
 
7 hours later…
8:51 AM
@smci true, I only meant that they definitely aren't asking for explode
 
 
1 hour later…
10:18 AM
6-rep self dupe; I didn't know that was possible
 
10:50 AM
Is there any way to pass on input from a executable to python?
./program | python or something?
 
Yes
I think something like that should work. Try python <<<'print(hello world")' if you're on bash
Oh, you mean as stdin? That should work too, regardless of python. foo | bar will pass foo's output to bar's stdin on linux
(But without any other command line args python expects source code on stdin, I think)
 
./times-up | python3 -c "x = str(input()); print(eval(x[11:]))"
this works but I think I need to pass that print back to the program
 
that should be done inside your program, like calling subprocess in python
eval(x[11:]) on user input; brave
 
it's a series of number addition
I think I need to figure out how to interface with a program, reading from stdout, and writing to stdin
 
Indeed
 
11:07 AM
what do I google?
All the SO answers so far seem a bit too complicated and old
 
If you want to do that in python you probably need docs.python.org/3/library/subprocess.html
I don't think you can (easily) latch onto an existing process
(gdb and friends are black magic)
You can use some kind of interprocess communication if both programs anticipate it
 
11:28 AM
But how do I read and write back to it?
Okay so I run the program with subprocess Popen I think
 
Your use case is a bit unclear to me. But I have to leave for a while
 
Oh the times-up program outputs a list of numbers and you need to evaluate and send it back
 
11:51 AM
Why not let times-up do the computation? :P
 
it's a compiled executable
(this is for a CTF)
googled my way to it
import subprocess
f = "/problems/time-s-up_2_af1f9d8c14e16bcbe591af8b63f7e286/times-up"

p = subprocess.Popen(
    ['stdbuf', '-i0', '-o0', '-e0', f], stdin=subprocess.PIPE, stdout=subprocess.PIPE)
z = p.stdout.readline().decode()
z = eval(z[len("Challenge: "):])
p = subprocess.Popen(
    ['stdbuf', '-i0', '-o0', '-e0', f], stdin=subprocess.PIPE, stdout=subprocess.PIPE)
print(p.communicate(str(z).encode())[0].decode())
any idea how to do it even faster? less that 200 ms?
(this is for level two)
 
user10984358
1:03 PM
heya guys, is there any other way other (efficient or more pythonic) than the following to see if two commands are identical?
 
user10984358
command1='ls -a -l'
command2='ls -l -a'
sorted(command1.split())==sorted(command2.split())
 
i like this approach, seems simple enough to follow
 
side note: make sure your command is really invariant under the permutation of command line args
 
user10984358
I might have 100 such flags, so the sort might not be an overhead here?
 
if you are worried about performance, a set comparison might be better, with the caveat that you trust the user/input not to have the same flags twice or so on
 
user10984358
1:06 PM
@AndrasDeak so far I don't think that is the case
 
user10984358
@ParitoshSingh I didn't really thing of that case :) but I have to handle it, but if that were to happen it will just take the recent one I guess
 
user10984358
can you do a call like so func(a='1',a='a')?
 
user10984358
if func is defined as def func(**kwargs)
 
try it out, see what happens
 
user10984358
>>> func(a=1,a=2)
  File "<stdin>", line 1
SyntaxError: keyword argument repeated
 
user10984358
1:09 PM
so I dont think I have to worry about that :)
 
user10984358
@ParitoshSingh are set(something)==set(something) better than the equivalent with list?
 
wrong question. set creation skips the sorting.
comparison itself shouldn't be different i assume.
 
user10984358
set comparisons are not ordered?
 
do you think sets have order?
 
user10984358
nope, idk why I even asked that
 
user10984358
1:12 PM
changed to set removed sort
 
user10984358
that is some takeaway
 
no no, it's fine, just was wondering if you knew about the "catch" with sets when it came to order or not. Sounds like you did, so it's good
 
user10984358
I was looking for a way to implement namedtuples in my code but I couldn't so I ended up creating a nested class
 
user10984358
not related to what I was asking btw
 
hm, any reason why you couldn't get namedtuples to work in particular that you can pinpoint?
 
user10984358
1:15 PM
well for each time a same command is called I have to change the output (one of the variables the class holds)
 
user10984358
it turns out you can't do Point.x=1 after you create them
 
user10984358
you have to do a _replace or something that returns a new namedtuple, I didn't bother looking further
 
user10984358
Point -> NamedTuple
 
tuples are immutable
if your usecase requires mutation, they wouldn't be a good fit
 
user10984358
they could make some light weight named tuples
 
user10984358
1:17 PM
I saw some recipes but I do mind using recipes I dont fully understand to begin with
 
that's a good call.
note that you can always use dictionaries to store key value pairs, that's one constant that you can always rely on
 
user10984358
my case it would be the sorted(command.split()) as key and the value would be the sub class I used
 
i see.
 
user10984358
the transition from set to sort is a significant improvement
 
user10984358
I had a friend suggest I create constants for all flags, and based on the split values do a sum and put it in a hash with the answer as key
 
user10984358
1:22 PM
anyways thanks for the input, have a nice day !
 
1:56 PM
Hi I want to ask a Python/Pandas question, but I am quite sure it will have been asked before....but I don't quite know what to Google. Probably just need the right vocabulary to Google to get me to the right answer. Can I ask for help here?
 
go ahead
and you don't have to ask for permission. Just ask
 
2:24 PM
Can anyone help me with this code. I have a list with private keys and I need code to separate 2-3 rights from the others and print their public address. This code requires a private key for the address, but it needs to be able to view the entire list and, when it comes across a fake key, just skip it and check the next one. Is it possible to do this with this code?

from bitcoin import *
priv = ('5KjYGE1N5yQmX4xVU8FEoL81DKMp7t2QEYx561PTMRCeyoM41sV')
pub = privtopub(priv)
addr = pubtoaddr(pub)
wifKey = encode_privkey(priv, 'wif')
 
2:58 PM
Or someone has some other idea? Please share
 
3:13 PM
I have .CSV file with list of private keys. But just 2-3 are valid the rest are fake because I wanted to hide them there. But now i lost my directions and don't know where are my private keys. That's why I need this
 
Do you have a way to tell whether a key is valid or not?
 
When the key is OK print (addr) but when is not they just give me error. I don't have solution when key is not valid
You can try yourself. Just change V to something else and you will get error
 
So, what's the problem then?
 
3:28 PM
The problem is because I have a huge list of private keys.
I can't check one by one
 
do you know how to write a loop?
 
> Advantages: No classes
^ wow
(from the description of the bitcoin module)
 
at a high level, i think you basically need to read the text file, take each key, and run a check in a loop
 
Yes I need that @ParitoshSingh
 
That module seems to be no longer maintained
 
3:32 PM
have you tried writing the logic for that? are you familiar with how to write a loop in python?
 
@ParitoshSingh Ca I tried but without success. When I write false key I just get error and that's all
 
what error exactly do you get?
 
I don't know exactly I work on this from Friday
I tried many options
 
can you copy paste the error message here?
 
Yes, just a second
When I add one more key
priv = ('5KjYGE1N5yQmX4xVU8FEoL81DKMp7t2QEYx561PTMRCeyoM41sV', '5KjYGE1N5yQmX4xVU8FEoL81DKMp7t2QEYx561PTMRCeyoM41sk' )
I get return _compile(pattern, flags).match(string)
TypeError: expected string or bytes-like object
 
3:40 PM
you've passing it a tuple of two items. that's definitely not what you should be doing
i do think you should actually go through some kind of tutorial on basic python syntax and programming if you want to get anywhere with this
 
OK. Can you give me some directions?
 
that aside, what happens if you pass just a single wrong key? say, priv = '5KjYGE1N5yQmX4xVU8FEoL81DKMp7t2QEYx561PTMRCeyoM41sk' ?
 
Ok. Just a sec
 
(i assume that's a wrong key. i don't know though, you have to tell us what's the right key and what isnt)
 
This is random right key. But random. No money
 
3:43 PM
okay, so simple question. can the code differentiate between a right and wrong key?
try a key which you know is wrong.
 
When I put wrong key I get error assert bin_dbl_sha256(data[:-4])[:4] == data[-4:]
AssertionError
This is with wrong key
Just get error
 
A wrong key gives an AssertionError?! There's got to be a better bitcoin library than this unmaintained thing
 
assert key_is_correct()
 
With assert key_is_correct() I get again assert bin_dbl_sha256(data[:-4])[:4] == data[-4:]
AssertionError
 
sorry, I was just making a non-serious remark
 
3:48 PM
I have no words
 
Why?
What I do?
 
I'll go back to lurking
 
Try something along the following snippet
with open("your_text_file_with_keys.txt", "r") as f: #CHANGE THE FILE NAME HERE
    content = f.readlines()

for line in content:
    try:
        priv = line.strip()
        pub = privtopub(priv)
        addr = pubtoaddr(pub)
        wifKey = encode_privkey(priv, 'wif')
        print (addr)
        print ('WIF Key: ' + wifKey)
        print("Correct Priv key:", priv)
    except AssertionError:
        print("key is wrong")
 
@ParitoshSingh I will try. Thank you
I get this error line 8, in <module>
pub = privtopub(priv)
NameError: name 'privtopub' is not defined
 
you need to keep your import line at the start as usual. from bitcoin import *
and you will definitely need to consult a tutorial on python in general at this rate.
 
4:00 PM
Thank you. I forgot that
@ParitoshSingh Your code work. Thank you so much
 
no worries
if you decide to make any modifications, or work on programming in general though, start with some kind of tutorial course. the code usually tells you what's wrong, but you need to invest the time initially to understand the error messages and so on. Regardless, good luck!
 
4:13 PM
Thank you again. Good luck to you too
 
Sam
5:08 PM
is it just me or did google do something to prevent people from using the free speech api (SpeechRecognition on pip, speech_recognition as python module)?
Last week everything worked fine, amazing recognition, now it can't even detect "hello"
		global listening
		r = sr.Recognizer()
		with sr.Microphone() as source:
			if (listening == True):
				Thread(target=playsound("./dep/tone.mp3")).start()
			self.debug("Waiting for input. . .")
			gui.listen()
			gui.micAnimation()
			audio = r.listen(source)
			gui.cancelListen()
			gui.stopAnimation()
			try:
				self.debug("Input closed")
				#text = r.recognize_google(audio)
				#text = r.recognize_google(audio, key=None, language='en-US', show_all=False)
				text = r.recognize
				gui.changeText(text)
im using a rather long code, but it works. Could it be that in previous functions i have very very many threads?
at least, it worked
Sorry, i took the unfinished code, the text = r.recognize is supposed to be the first commented line: text = r.recognize_google(audio)
 
user10984358
5:30 PM
heya guys, so if i have to run a couple of external commands(subprocess.run)from my python script, is multiprocessing or threading module for me or neither?
 
Based on that information alone, neither is a requirement. You can just shell out and wait for it to run... If you're needing to just background it and do other things. I would suggest asyncio
https://docs.python.org/3/library/asyncio-subprocess.html
Disclaimer: I don't know much about asyncio in practice. But, it's been catching my attention more than multiprocessing/threading for most problems
 
user10984358
5:51 PM
thanks for that, will look into that
 
6:09 PM
@Sam Thread(target=playsound("./dep/tone.mp3")).start() is a horrible way of writing playsound("./dep/tone.mp3")
You want target=playsound, args=("./dep/tone.mp3",)
 
user10984358
6:50 PM
I have this small situation, how can I do this on multiple dicts with a map, without getting this error?
 
user10984358
>>> def fun(**kwargs):
...     print(kwargs)
...
>>> d=dict(one=1,two=2)
>>> fun(**d)
{'one': 1, 'two': 2}
>>> list(map(fun,**[d,d]))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: type object argument after ** must be a mapping, not list
>>> list(map(fun,[**d,**d]))
  File "<stdin>", line 1
    list(map(fun,[**d,**d]))
                   ^
SyntaxError: invalid syntax
 
I don't understand what you're trying to do
 
user10984358
the map is actually a method of ThreadPoolExecutor context object
 
Hi, I'm running these few lines:

from selenium import webdriver

chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument("--user-data-dir=C:\\Users\\James\\AppData\\Local\\Google\\Chrome\\User Data")
chrome_options.add_argument("--profile-directory=Default")
driver = webdriver.Chrome(chrome_options)


And getting the error:

File "C:\Python37\lib\subprocess.py", line 530, in list2cmdline
needquote = (" " in arg) or ("\t" in arg) or not arg
TypeError: argument of type 'Options' is not iterable
 
user10984358
something like this
    with concurrent.futures.ThreadPoolExecutor(max_workers=3) as executor:
        executor.map(thread_function, range(3))
 
user10984358
6:53 PM
this is where i saw this code, i am changing this to my needs realpython.com/intro-to-python-threading
 
for dict1, dict2 in pairs_of_dicts:
    func(**dict1, **dict2)
^ that's what you want to do with a ThreadPoolExecutor?
 
user10984358
yeah but I can have arbitrary number of dicts
 
user10984358
no
 
user10984358
wrong my bad
 
user10984358
func(**d1) then func(**d2)
 
user10984358
6:56 PM
just like a normal map call, apply that function to all the elements in the iterator
 
I think the only way to do that is with a helper function
 
user10984358
no built in syntax then huh ? :(
 
pool.map(helper, list_of_dicts) and helper = lambda kwargs: func(**kwargs)
@JaAnTr 20 seconds of googling told me you need webdriver.Chrome(chrome_options=chrome_options)
 
user10984358
what you said works perfect
 
user10984358
does it still have the same benefits the ThreadPoolExceutor give? will it slow down or something?
 
7:02 PM
no noteworthy downsides
 
user10984358
will using this cause "race conditions" ? I read about those not in depth though
 
user10984358
by this I mean ThreadPoolExecutor
 
nope
 
user10984358
well the command is supposed to return a list of length 3 for the first argument and list of 2 for the second argument
 
user10984358
but when I run I only get two in both cases, if I just pass in one argument, I get the a list of three as required
 
7:06 PM
Not sure what you mean by "if I just pass in one argument". Can I see the code?
 
user10984358
one sec
 
user10984358
o.getDevices(d=d1)
 
user10984358
d1 is a dict of flags
 
user10984358
o.getDevices(d=d1,d2=d2)
 
user10984358
so this function uses Thread to execute my function that returns a list
 
user10984358
7:07 PM
so for the first call with one argument it returns a list of length 3 the correct output
 
user10984358
in the second call with two arguments it is supposed to return two lists one of length 3 and one of length 2, but i am getting 2 list of length 2
 
user10984358
if I change the max_worker to 1 in the ThreadPool thing I get the intended lists
 
user10984358
ok hold on
 
Well, this is just speculation, but if the value of max_worker affects the output then it sounds like the function you're multithreading has race conditions
 
user10984358
7:10 PM
yeah thats what I was about to type
 
user10984358
all the functions use the same object to call
 
user10984358
I am sure that is what the problem is
 
user10984358
what can I do to get around this, my code runs at least 10 seconds faster with this implementation
 
hard to say without knowing anything specific, but that object that every thread uses must implement some kind of locking (or find another way to become thread safe)
though that might then defeat the point of multithreading in the first place
 
if the "object" being used is "input" to a function, and you perform mutations on it, just make sure your first order of business is making a copy of it inside the function itself.
im assuming here that the multiple threads are indeed "supposed to be" working independent
and in case of nested objects, make sure it is a deep copy.
 
user10984358
7:15 PM
so if I have 50 arguments to my getDevice function I make 50 copies?
 
user10984358
because each argument is a separate call (max_workers), that is where I am using the multithread
 
are my assumptions valid for your use? (that 1. it's the input. 2. there's mutations to it. 3. the input was supposed to be independent)
 
user10984358
all but 3
 
so, is this supposed to be sequential then? that the 2nd thread should be using the output of first thread or so on?
 
user10984358
yup in a way
 
7:18 PM
then don't use threads
 
user10984358
so when a first thread returns a list of length lets say 3, I delete 3 elements
 
user10984358
then the second thread must use the remaining
 
user10984358
ohh, then how can I speed it up?
 
have you profiled your code?
 
user10984358
I dont know that is
 
user10984358
7:19 PM
benchmark?
 
yes, find out what's slowing you down
 
essentially, it's a detailed benchmark, which can highlight what portions of code take the most time
 
user10984358
well if I were to say it could be the subprocess calls
 
there's the profile module
 
user10984358
but I will see how to actually do that
 
7:21 PM
never treat multiprocessing/multithreading as a silver bullet. it isn't. your first step if persuing performance should be making sure the code itself works well
 
user10984358
so once I profile what should my course of action be?
 
And when you have situations like these where the next iteration depends on the output of previous one, it becomes difficult to correctly use parallelism. In those cases, unless you go back and figure out a different way to break the links between the code itself, it's just simpler to stick to single threads
 
user10984358
each subprocess call takes at least 10 seconds to run
 
see if there's areas that are taking more time than they should, and then see if you could improve on the logic
 
user10984358
I will go through my code see if I can do some design changes
 
user10984358
7:24 PM
appreciate the help !
 
7:49 PM
mini-riddle:
>>> _ = 1
>>> 2
2
>>> _  # will this be 1 or 2?
 
i guessed wrong, and in hindsight i have no idea why i guessed it that way.
 
I'm not really sure if there's a reason why it's implemented the way it is. If you don't know the answer, it's pretty much just a 50/50
 
8:08 PM
Another interesting tidbit - what'll be the output of this:
aran-fey@paul-laptop ~> python -c 'import sys; print("__main__" in sys.modules)'
 
9:00 PM
"Thanks a lot for the answer! +1! Anyway, it doesn't work at all!" <- OP logic
 
cbg all - just a quick check in. Been away for the weekend.
@Aran-Fey Following on from this session:
>>> del _
>>> _
What will happen?
 
9:19 PM
Nope!
Well, my 3.6.5 didn't ayway. I've no idea how consistent the behaviour is across releases.
 
sounds awfully unguaranteed
 
I would certainly caution against any expectation of consistency.
OK, standup in 9.5 hours. Off to beddy byes for me. Rhubarb!
 
rbrb
 
9:56 PM
@MisterMiyagi it took me a while but I've finally learned who your name refers to :D
 
 
1 hour later…
11:18 PM
They are both dead now @AndrasDeak
 

« first day (3270 days earlier)      last day (1683 days later) »