« first day (2524 days earlier)      last day (2649 days later) » 
04:00 - 16:0016:00 - 00:00

16:23
hey, i need someone to test my python app. Anyone interested?
@ChaseBarnes welcome, you may want to take a gander toward the right top side of your screen where it says 'Room rules:'
it'll help a lot ;)
16:27
does anyone know this selenium bug
will these rules interfere with my question?
not yet ;)
@SohaibAsif are you sure the bug is in Selenium? Sounds like your web server returned something besides 200 OK or whatever valid codes are
Granted I'm not certain, but that's what it appears to be
@SohaibAsif There seem to be an error in line 1...
you'd have to double check to be sure
16:29
Speaking of testing: I discovered Postman recently and really like it.
So, for my question, can anyone try it out?
e.g. use fiddler or something like it
I already use that, but I need another human to test it. I need a differect perspective.
different*
@ChaseBarnes tip: github makes it easier for people to try things.
what is that?
16:30
I've only looked at the source code so far, but I already dislike all the pointless time.sleep(...) calls
yes fiddler is nice with scripting / filters
well, that is to delay the print lines, to make it smoother
I was just going to ask about that, heh.
okay
anything else worth changing?
def slowprint(lines):
    for line in lines:
        print(line)
        time.sleep(0.1)
16:32
Surely you have a method that takes an array of strings and print()s them with a time.sleep in between
then you can just do...
Heh. Yeah, like that.
whenever i start i get this pastebin.com/HmfmEfwv
I dont understand that lol... I am a beginner.
I guess it's not a big deal for a starter
16:32
but after third attempt selenium webdriver start working correctly
it happens everytime
It'll just make your code much nicer when you understand what it's doing
@SohaibAsif Check the module. Maybe it is misspelt?
okay
slowprint(['-'*50, 'This defines BOLD text. This has a specific use', ', such as (<p>Hello <b>World</b>!</p>)', '-'*50])
HELPTOOL()
or even better:
that will work?
Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
slowprint(['-'*50, 'This defines BOLD text. This has a specific use', ', such as (<p>Hello <b>World</b>!</p>)', '-'*50])
NameError: name 'slowprint' is not defined
sigh
16:35
i am using Python 3.2, does that affect it?
3 mins ago, by Wayne Werner
def slowprint(lines):
    for line in lines:
        print(line)
        time.sleep(0.1)
@Kevin thankfully there are always more typists! Anyway, on to our real problem of code quality. Perhaps code review consultants can help? My friend owns a code quality consultancy that could definitely fix this in five expensive years!
nopx no misspelling
16:36
@ChaseBarnes nothing to do with what they're saying, but in general 3.2 is not considered a great version. 3.4 or greater is a safer bet
then, I cannot help you, because I know not where the error is located
okay. I shall install a later version
@SohaibAsif Verify that what's returning to selenium has a valid status line, cause that's what it's complaining about
@Rawing okay, is there a way to print them on the same line?
Result
>>> import time
>>> slowprint("hello")
h
e
l
l
o
remove the time.sleep(...)?
16:38
I shall try that
you're supposed to pass in a list of strings: >>> slowprint(['hello'])
same result
I misunderstood the question. Try the list.
slowprint expects a list of strings
16:40
so, how shall I put it into the interpreter?
if you just pass it a string, it does exactly what you see it do
DSM
DSM
In [4]: slowprint(["hello", "a", "b", "cde"])
hello
a
b
cde
2 mins ago, by Rawing
you're supposed to pass in a list of strings: >>> slowprint(['hello'])
I see. I'll try iy
it*
DSM
DSM
In the first two minutes after you post, you can edit your message.
16:41
@WayneWerner Feels like we're playing comment ping pong.
@Rawing just need two more and then we can determine who serves first ;)
wait, but how do it put it like:
Hey, anyone want to help me fix what looks like broken pip?
-----------------------------------------------
The <div> tag is used to create a 'box' that co
ntains everything that you put between these ta
gs: <div> </div>. This can be used for creating
interactive menus, navigations bars, and more!
-----------------------------------------------
16:43
@ChaseBarnes make a post on code review and I can write a long explanation of improvements to make
How can I do this?
DSM
DSM
Wait, so now we're reimplementing wordwrap?
??
@Erich How can I do that?
@ChaseBarnes This link: codereview.stackexchange.com. Carefully read ALL of the rules twice before posting. Otherwise it will be removed.
@Erich Okay, thanks! I'll send you a link when it is posted
DSM
DSM
16:46
In particular, note that Code Review is for reviews of working code, not code that does X when you want it to do Y.
Seems like his code does X and he wants it to do X
just wants people to try it out I guess and make sure that it does X for them, too :)
DSM
DSM
X for everybody! \o/
no, I just want to improve the code, and for people to have a differect perspective on it.
its not really, pretty, ya know?
Just download it and run it if you want, just to review it
and it is saying i can only post once every 40 minutes..... for some reason
@Erich Can you give me a sample of the slowprint using some of the code in my app?
17:12
0
Q: HTML HELP TOOL: displays basic HTML tag uses

Chase BarnesI need someone to review and improve this code. import time import os, signal User_Name = (input("What is your name?: ")) # If blank twice, sets to John if User_Name == '': print("Please enter a name") time.sleep(1) User_Name = (input("What is your name?:...

You might be able to refactor a little, by making those sleeps a function that you call, but I don't know if that's worthwhile.
Why do you have time.sleep(0.1) several times in a row, rather than time.sleep(0.5)?
for i in range(0,100): i+=1
print i
i saw this in someone's code
17:32
facepalm
designed noop
working as intended
wim
wim
17:49
@DSM an iPhone X? yes please
here I am with my Moto G and they are already up to X... :D
Hi guys
I need a little help
A little lemon juice will get that stain right out
what if it's an invisible ink stain?
DSM
DSM
17:56
The thought of lemon juice revealing a secret treasure map is going to make me happy for the rest of the day. So thanks for that!
If it's invisible ink, then lemon juice will not get it out. Lesson: only use lemon juice on parts that have visible stains, and not parts that may be invisibly stained with things that will become visible when you put a little lemon juice on them.
Should use lemon juice XOR stain is visible = False
Hey
How would you recommend saving a pandas series directly into an existing excel sheet at a specified location, overwriting what is already there?
@wim you can have mine.
hi.....I have a scraper made....I need someone from US to check it for errors(scrape contents are google ads.....not showing in my country) .....pleaseeeee
So I'm undergoing a files directory restructure, and basically if I hit a subdirectory named "NO_DIV" I need to move the contents into the parent folder. Should I be using recursion here alongside my next(os.walk(path))?
the contents could be directories with files etc, or just files
18:10
You're not really supposed to call next manually on os.walk
I mean, like, you can, but why would you want to
I'll be honest I'm not fully aware of what it's doing. it's just an iterator right?
subdir = next(os.walk("%s/%s" % (root,country)))[1]
for dir in subdir: #iterate the years
I use it like this
(2.7)
99.9% of the time you want to call it like for dirpath, dirnames, filenames in os.walk(path): and no recursion is necessary whatsoever for it to iterate over every directory contained in path
for dirpath, dirnames, filenames in os.walk(path):
    for dirname in dirnames:
        if dirname == "NO_DIV":
            place_where_files_are = os.path.join(dirpath, dirname)
            place_where_files_will_go = dirpath
            move_files_somehow(place_where_files_are, place_where_files_will_go)
Something like that.
Oh interestinggggggg
thank you Kevo <3
Hello, I have a general question related of implemented some method from class or some function. For a function for which is requered to return some value, must have return statement on the final in this body? Can this display the result? This implementations can be consider equivalent?
displaying something and returning something is not equivalent, no.
18:18
All functions return a value regardless of whether it has a return statement or not. Functions that execute without explicitly returning, will return None automatically.
And the return can be anywhere in the function, does not have to be on the last line
>>> def f():
...     x = 23
...     y = x * 2
...
...
>>> return_value_of_f = f()
>>> print(return_value_of_f)
None
I'm agree 100 % with that. But I just put question to test if can be in some condition to "look" equivalent
I don't understand what that sentence means.
Are you asking, like, "is there a functional difference between these two approaches?"?
def f(x):
    if x:
        return 23
    else:
        return 42

def g(x):
    if y:
        y = 23
    else:
        y = 42
    return y
I can put also others examples, and also I can explain some consequence for portability in design for these. But I prefer to discuss with other...to see if can be other opinions
18:20
They compile to different byte code, but that should basically never make any difference
Are you asking:
781
Q: Should a function have only one return statement?

DavidAre there good reasons why it's a better practice to have only one return statement in a function? Or is it okay to return from a function as soon as it is logically correct to do so, meaning there may be many return statements in the function?

So is a fundamental different between using return statement and use something related to print.
As far as I am aware, the Python community does not strongly believe in Single Point of Return. Have multiple returns if it makes things easier.
@user1929959 as Rawing said, printing and returning is fundamentally different
when you print, the result is shown on standard output, then the value is discarded (lost forever!)
Yes, agree
you typically only want to print when you want to print; otherwise your function should return something
18:23
In response to that, coding some graph traversal algorithms would be incredibly more tedious if you could only have one return statement
Is about portability of function or method
I don't see how this relates to portability
In general speaking, but yes good point "is lost forever"
but there might be a language barrier here
Portability I guess that you can reuse this function
18:25
Well, yeah. Most functions in the wild have some task to do, and unless the task is only about printing, a return value is more often than not used by the caller
correct me if i'm wrong but python cleans up all local variables in a function once it exits and leaves the scope.
So if you want some to reuse you can not put print
This is a huge generalization, but: once you get beyond the "learn Python in 30 days" stage, the vast majority of your functions will have no print statements in them, and very many of them will have return statements.
I discuss as general principle
you can print and then return from a function, if you want to do both
18:27
The primary purpose of functions is so you can reuse them. If you only needed to execute code once, you wouldn't put it in a function.
@Erich Mostly, but some variables live longer thanks to closures.
@Erich ones that don't have any references to them
if you snatch the return value, it's kept around
yes, but I refer to the situation in that you substitute return with print, and these sound sucks or very very stupid :)
@Erich That's a bit too unclear to be wrong :P If you're saying it destroys all references that were held by that function, then you're right. If you're saying it destroys any objects, then you're wrong
>>> def f(x):
...     def g():
...             return x
...     return g
...
>>>
>>> h = f(23)
>>> print(h())
23
Here we see that x lives past the line where you call f. If it was collected at that point, it would not be around to get returned by h.
Thanks for express your opinian Andras
I correct it
18:29
thank you:)
how is this legal:
>>> def foo():
... pass
...
>>> foo.a = 0
>>> print(foo.a)
0
monkeypatching
looks like I have some reading to do!
functions are objects like everything else. As long as it has a __dict__, you can add as many attributes to it as you want
but I can't reference it with self like I would with an object
or is that possible
DSM
DSM
18:32
Add print(foo.a) inside the function and see!
ahhhhh, okay. I figured it out, thanks all!
functions have no self as such, but they can still refer to themselves without using their own name with this simple trick:
def foo():
    import inspect
    frame = inspect.currentframe()

    for obj in frame.f_back.f_locals.values():
        if getattr(obj, '__code__', None) is frame.f_code:
            self = obj
            break

    del frame

    print(self)

foo()
so, uh anyone done some kind of work with compiling python modules on windws? I can't seem to find out how to tell it to find a certain static library
it compiles fine but then it barfs linker errors everywhere
DSM
DSM
@Rawing: I'm calling Zen violation on you. ;-)
That's a lot of work to avoid using a class instance
You could collapse that for-if-break loop to:
self = next(obj for obj in frame.f_back.f_locals.values() if getattr(obj, '__code__', None) is frame.f_code)
18:52
we were doing code review earlier, are we doing backwards code review now? :p
less lines = less complexity, obviously
I need to figure out if you can embed arbitrary metadata into pdfs. Orrrr I could read funny posts on twitter. Hmm.
Why not embed arbitrary twitter posts into pdfs? two birds, one stone.
DSM
DSM
And then we can uuencode the pdf! For portability.
@PM2Ring: d'you remember the uu-days? ;-)
very crap portability cases should be called porta-potty
19:00
Google says that you can embed metadata into pdfs. Now I need to figure out how to do it programmatically. Orrr I could see if there are any easy questions on SO I can farm
19:19
Can we encode PDFs such that they post on twitter when opened if the user is currently logged in to twitter?
Then instead of read responses, I can simply monitor a hashtag I pick on Twitter.
No, that's called CSRF, and is prevented on any decently-secured site.
For example, you could use Flask-WTF or Flask-SeaSurf to protect against CSRF in a Flask application.
cabbage
Does anyone know of a tool that can search every column of every row of every table of a database for a given value? Extra points if it will match a regex.
Dump the database to a SQL file then grep it.
that can be a good place to start. Thanks.
ideally, I need to know which table, row and col the value comes from
Write a better regex. ;-)
Non-jokingly: you could reflect the tables with SQLAlchemy then build a query for each table over all columns in each model. It would be insanely slow, but it would get you what you want.
Actually, the simple grep would give you the tablename and column name.
19:31
@davidism That's probably for the best. Although autotweeting "I just opened a PDF about the vaccine clinic coming, let's see how long it takes me to response to the Nurse...#don'tdoitthedaybefore" ...would be more fun than what usually happens.
19:53
@AnirbanNag'tintinmj' welcome, please read our room rules, don't post recent questions here
cool
can i get access to that room
why would you wanna go there? are you good at evading knives? :s
No, why would you need access to the trash? Also, your question is a pretty easy to find duplicate.
stackoverflow.com/q/46205484 dupe, had to edit in the python tag so my hammer broke
20:17
question
let's say you have this
[a] = ['bob','charlie']
[b] = ['car','mansion']
you want to append these 2 lists into a list, but keep the format
so you do that
c = []
c.append(a)
c.append(b)
is there a way to make the whole thing, less ... manual, please?
c = [['bob','charlie'],['car','mansion']]
DSM
DSM
I don't know what [a] = ['bob', 'charlie'] is meant to do, but why not just do c = [a, b]?
above is my result
@DSM oh man ... that simple -_-'
cheers DSM
:39134384 I don't want a flat list
I realized that after I spoke >.<
@Erich no worries ;)
rb (good night folks)
20:33
Hi!

Is there a way to solve for x symbolically using python, like this:
http://www.wolframalpha.com/input/?i=solve+for+x+a-x%3Db-x
Python silently eats AttributeErrors that happen in a getter function and calls __getattr__ instead -.-'
class Broken:
    def calc(self):
        return self.value # throws AttributeError

class Working:
    def __init__(self):
        self.brokenobj = Broken()

    @property
    def prop(self):
        return self.brokenobj.calc()

    def __getattr__(self, attr):
        return 5

print(Working().prop) # output: 5
python pls. give me back the last 20 minutes of my life I just wasted because of this
it can eat you too as far you don't know how to play with it
@Rawing that seems crazy at first glance, but I suppose it makes sense!
(Nice MCVE)
just the attribute here that works
20:49
huh, thats kind of interesting. Python must consider the brokenobj to be an attribute I guess?
I've encountered similar kinds of silent error swallowing a few times
>>> it = (x for x in range(3))
>>> list(next(it) for _ in range(5))
[0, 1, 2]
eclectic !
snakes swallow way too much
Anacondas can swallow a whole deer
or alligator
sorry, make that crocodile
@Funkyguy I assumed that the @property annotation means it uses the ____getattr____ method to figure out what to do rather than actually run the code in the prop method
Slightly too many underscores there
Yeah
Still works the same in my 3.7.0a0 build...
wim
wim
@Rawing __getattr__ is used when AttributeError is caught. how do you propose Python to distinguish between an AttributeError from a bug inside your property and an AttributeError from an attribute not being there?
I consider it a feature that properties can choose to "not exist" by raising an AttributeError
that's a feature? I'd rather get an exception
and surely it can't be difficult to check if an AttributeError was raised inside a __get__ or whether no such __get__ even exists?
wim
wim
Really? I think that would be difficult. How would you do that, without tying the hands of implementations other than CPython?
like, there has to be a mechanism in place that calls the property's __get__ function. All you have to do is to not catch AttributeErrors raised during execution of that mechanism
wim
wim
21:11
note the behaviour is consistent with hasattr
>>> class A:
...     @property
...     def foo(self):
...         raise AttributeError
...
>>> hasattr(A(), 'foo')
False
would you want that changed too?
I would. I don't think that feature is as useful as a proper exception traceback
@Rawing: __getattribute__ is responsible for calling __get__, but __getattribute__ is not responsible for catching the AttributeError.
and it's not like "changed" equals "removed" anyway - they could keep that behavior, but with a different exception and/or only if it's raised directly in the getter
The AttributeError is caught in the code that calls __getattribute__, and that code would have a very messy time trying to figure out where in __getattribute__ the AttributeError occurred and whether the AttributeError was deliberate.
you're saying that __getattr__ is called if __getattribute__ throws an AttributeError?
wim
wim
21:17
canned use case:
Yes, that's what triggers __getattr__.
wim
wim
>>> class Car:
...     def __init__(self, color):
...         self.color = color
...     @property
...     def colour(self):
...         return self.color
...
>>> car = Car('red')
>>> del car.color
>>> hasattr(car, 'colour')
False
Hmm, I see. That'd be messy to change I guess. But would it be horrible if you had to throw a PretendIDontExistException instead?
Sure, that disappearing colour property is handy, but it might just as well be a bug in your code. If you do if not hasattr(self, color): raise PretendIDontExistException, it'd be clear that it's intentional
wim
wim
I think that's a case of If the implementation is hard to explain, it's a bad idea.
To protect yourself from misbehaviour due to creating some obscure bugs due to this thing, the way is having lots of tests, not overcomplicating the language implementation.
I don't know, I don't think it's particularly complicated. But I guess that shouldn't be a surprise, because it was my idea.
21:26
Exceptions for control flow have their downsides; it's sometimes hard to distinguish a legitimate problem from ordinary control flow.
wim
wim
This, however, was a Python bug (catches any error)
evolution of the snake
every day my choice to stick to python3 is reaffirmed, thanks wim
@RobertGrant Huh I hadn't even seen that property decorator
 
2 hours later…
23:12
Hi, I'm trying to make my own custom list (dynamic array) using class on python, I got a "AttributeError: 'py_object_Array_40' object has no attribute 'append" when trying to copy the array element by element with a for loop when resizing it, or a memory error when trying to copy it by slicing [:]. Any ideas why?
04:00 - 16:0016:00 - 00:00

« first day (2524 days earlier)      last day (2649 days later) »