« first day (2663 days earlier)      last day (2284 days later) » 

12:03 AM
Seems to use os.scandir
 
wim
ok, and os.walk uses scandir too
 
12:30 AM
wim has left us for the greater good - went off to answer typo questions. :davidism:
 
evening cabbage
 
 
3 hours later…
4:06 AM
Does this room recommend any good materials/books/blogs on design patterns and problem solving in python?
 
4:44 AM
Huh, good thing I removed my 7 vote answer on yield from in list comprehension from the "What does the yield keyword do in python" question.
 
 
2 hours later…
6:40 AM
cbg
 
6:55 AM
Apparently, upgrading to 3.7 is the answer to some questions
 
7:09 AM
cbg
 
Morning
 
Can anyone here help me with flask-socketio?
 
@ashwani Don't ask to ask, just ask. See room rules.
 
7:24 AM
Jul 11 '16 at 16:50, by vaultah
@user please read http://sopython.com/chatroom
 
I have a flask backend application which uses socketio.emit() to send data. It is deployed on cloud. Now I am trying to make a react front-end for it locally to receive that data using socketIO. But it gives me Access-Control-Allow_Origin error. I have even enabled CORS using flask-cors but still it shows the error. What am I missing here?
 
If you still get CORS-related error, then you might have misconfigured it. Wouldn't know much unless you show the relevant settings / code. In which case, this can be better answered on the main site.
 
7:40 AM
cbg
 
 
1 hour later…
9:00 AM
@AshishNitinPatil But wsgi is a server that maps a request(i.e., Apache(C) api) to python wsgi api, Isn't it?
guniconrn, uWSGI etc...
Am not sure, how wsgi.py will do this job, after installing django
 
@davidism oh I love that, cheers mare! it is incredible, how simple shapes and simple motions can have such a variety of combinations which attract us after all this time, isn't it?
 
@overexchange WSGI isn't a server. wsgi.readthedocs.io/en/latest/what.html
 
9:51 AM
@ThiefMaster If I work with mod_wsgi, then it is a loadable C library(.so) linked with httpd.
$ /usr/sbin/httpd -M
Loaded Modules:
 core_module (static)
 mpm_prefork_module (static)
 http_module (static)
 ...
 ...
 wsgi_module (shared)
Syntax OK
This C library(mod_wsgi) is linked to httpd executable(C). This converts http requests(C api) to wsgi api(python), so that frameworks like django/flask can understand. Because they follow wsgi interface
This is what you meant in your reference, It is a specification that describes how a web server communicates with web applications(django/flask/..)
 
From my understanding, your server will communicate with the wsgi.py via the wsgi_module
 
@overexchange "wsgi" itself is still not a server :)
 
wsgi_module being the "library" for your server, to interact with the middle-man wsgi, which interacts with Django/ Flask
 
@JonClements Hi, Can we talk for a minute ? :)
 
10:15 AM
Cabbage
@wim That happened this morning :)
 
10:36 AM
@AshishNitinPatil Ok then, where are we installing wsgi_module? when we follow django documentation to install django
@ThiefMaster yes, wsgi itself is not a server
Doc talks about wsgi amidst deployment of django but not before writing an app.
 
@overexchange wsgi_module is something that belongs to the server and nowhere related to Django. I gave that as an example from your httpd modules from above comments
For different servers, the module / library can be different, but they will ultimately talk to some wsgi.**py** which talks to Django
And please note, my knowledge regarding wsgi is pretty limited. You should get clarifications from other places / people too.
From my experience, deploying Django apps is always a pain, no matter what guide / tutorial you follow. But the whole scenario is very different if you use containers, or a standard template for a django project. I have been using Cookie-cutter Django and I've never had to worry about setting up any kind of environment, be it development or production.
 
 
1 hour later…
12:00 PM
Just wondering if anyone's using VStudio Python tools? I would like to be able to import a function from one of the other files in my repo, and get intellisense to prompt arguments etc. This answer to a similar question looks way too messy; I'll have to move my whole repo into a specific place on my computer?! Don't seem to have to do that with Spyder (apparently)
Is there a simpler way to do this, I'm a bit of a green-bean and maybe I'm overcomplicating (don't know what the __init__.py is all about), do I have to move my repo into the new save location? Using Python 3
 
@Greedo I don't think moving your repo is going to help. That's for when you're trying to import another self-made module.
Honestly, trying to make intellisense work with python code is a bit of a sisyphean task - it's likely you'll never get it done.
But then again, that's based on my experience with PyCharm. Maybe VS is better.
 
12:17 PM
@Rawing do you happen to know what I should be trying theoretically to get it to work
Just stick an empty __init__.py in every folder perhaps?
 
Nope, sorry. Really, as long as you can import the function in your code, intellisense should also work. If it doesn't, well, I don't know how to trick VS into working anyway.
 
@Rawing OK great XD, VS is a tricky beast, all of the imports work and I even get prompted with the function names in the modules, just not the actual arguments (like I am with library functions)
I'll see if anyone else knows how to get it working
 
12:46 PM
cbg
 
Thanks and done
 
It's a python question. Why mark it duplicate with C question ? There could be different details even though previous question explains backspace behavior in C. — Rahul 3 mins ago
 
12:56 PM
I have form like google forms which contains some question and next button. I wan to add previous button also. how can i efficiently handle previous button operation. is it need to store the user visited question list and current question in db?any help?
 
Maybe this will fix the intellisense: donjayamanne.github.io/pythonVSCodeDocs/docs/autocomplete
 
1:15 PM
@SaravananN what framework are you using?
 
@AndrasDeak django
 
@SaravananN You could always do that in plain html / js you know.
Unless it's a really long form where the user may just quit midway at times and then resume back
 
@AshishNitinPatil How can i implement this in server side?
 
1:34 PM
@SaravananN Im sure there is a better way but if users are closing out and getting back on. PHP and cookies isnt too difficult from what I remember on a past project. You could just have it save to a cookie and fill in the next time on load if a cookie exists.
 
@SaravananN My suggested solution was client-side. For server side, depending on your requirements / form length, things may differ. You could have a big model that stores answers for all the form inputs, and have them blank=True, null=True, and just save the model whenever form is submitted. This way, you will have all the previous data in your db.
 
Then tie the rows with the blank data in one field to the rows where that same data is not blank but it is for the same form_id]
 
Eh, like I thought, there's always a library for such triviality - github.com/django/django-formtools
 
Lazy solution: remove the Next buttons and put all of your questions on one huge page
 
yep, that's the simplest :D
 
1:42 PM
"But some pages only apply to a subset of users based on previous answers, such as 'what country are you from?'" you hypothetically say. No problem, do it IRS style: "If you answered PUERTO RICO for question 23.42, then leave questions 99 through 203 blank"
 
Js could check the form as you go if you want to get fancy with that
Else keep it simple like the IRS does.
 
I'm aiming for as unfancy as possible or else we're going to end up with more work than implementing a Previous button
 
(It's a feature)
(It's a feature) (This is needed for IE8 & below)
 
“for IE8 & below” WHY
 
Am making excuses for Kevin's excuses :-p
 
1:50 PM
It’s 2018. Even the most backwards-compatible thing we build for large companies at my company are IE9 minimum with most leaning to just IE11.
 
Until you have a customer with Windows XP.
Been there, not-wanted-to-do that.
 
@AshishNitinPatil There is not a single acceptable reason nowadays to not tell a custom with WinXP that they are on their own if they choose to use an insecure, unsupported OS
 
I know :(
 
@poke perhaps they need to be compatible with python 2
 
@AshishNitinPatil Been there too, that’s why I said IE9 is minimum. Not IE8.
Last IE to run on XP is IE9.
@ThiefMaster There is also no reason nowadays not to patch some basic support in for IE9 if the customer wants you to do that and is willing to offer you additional money :P
 
1:56 PM
@AshishNitinPatil @Kevin @ZackTarr Thank you.
 
@poke Only if it's a pretty decent amount of money that goes to the developers who have to deal with the horrible hacks the customer wants ;)
 
But what if I'm on the brink of insolvency and if I lose one more client then mean Mr Carruthers will foreclose on my combination startup/orphanage?
 
FWIW, the only place where I saw Windows XP being used recently was in the control room of a particle accelerator in China. Including the "this copy of windows is not genuine" notices one would expect there ;)
@Kevin Better to sell your body than your soul by developing for IE8 :P
 
Being able to tell clients to F off is a rare and beautiful privilege
 
Making a file stamp with the time, hopefully down to the millisecond with datetime. Is there anything fancy that can strip out the : from the time in str format? Or should I just manipulate it with the str class
 
1:59 PM
@ZackTarr why not generate the string with strftime using the formet you want
 
@ThiefMaster Ahh must have over looked that one. Ill use it. Thanks!
 
@ThiefMaster *IE9 x_x
@ThiefMaster There and on ATMs
 
@Kevin "We are pinned to 2.7. Why is that a problem?" "F off."
 
@AndrasDeak I was hoping that PEP link went to 373
 
but there's no "f" in "python 2 EOL"
 
2:13 PM
(and possibly PEP 404)
 
@ThiefMaster If you're suggesting that I seduce mean Mr Carruthers, it's impossible, as that man only loves money. And no, dressing up like a dollar bill didn't work, I already tried.
 
I want to send though a TCP socket a 2MB json. Should I encode it to HEX? Or should I send it as text? What's better in your opinion?
 
Converting an ascii string to a string of hex characters doubles the size of the message, so don't do that if you don't have to.
 
Btw. is there anything that would prevent the Python Foundation of pushing the EOL further into the future…? Just wondering if the future is as bright as we hope it to be…
 
Guido?
 
2:18 PM
That’s a “no”, right?
 
How so? If the BDFL is dead set on EOLing python 2 in 2020, there's nothing they can do, right? Question is whether he is.
 
That’s the question.
 
\o cbg
 
In flask I am using flask-sqlalchemy but I cannot see on the documentation any thing for creating a column with type tinyint and various others. Is there a way to do this?
Actually just read this;

http://docs.sqlalchemy.org/en/rel_0_9/dialects/mysql.html#sqlalchemy.dialects.mysql.TINYINT
 
2:41 PM
Guys How are you? I am a newbie.
 
Hmm, should stackoverflow.com/q/48524018/953482 be flagged as rude? The asker isn't being rude to answerers directly, but the code is rude to anyone that runs it.
 
my rule of thumb is: if it doesn't offend you, leave it alone
 
I did feel a twinge so I think I'd be in the clear flagging-wise, then. Kind of a moot point since it's closed now.
 
it did get rude-nuked
 
2:57 PM
"In Python I tried the 'fish'" is a pretty great title though.
How was your fish, sir? "Rude!"
 
Introducing the Python fish, an alternative to the Turducken for people that don't like the taste of poultry.
 
@mp252 see that red text that says LEGACY VERSION?
 
whoops, I did not see that!
 
Haha indeed it does, thank you
 
3:04 PM
"Legacy" usually means "a very nice thing that someone powerful gave us so that we'd remember them" so I always use legacy versions whenever possible
10
 
just google anything python, and you'll get Pythoff
 
The last ten times I used google to find out all the dunder methods I could overload, the official python docs weren't even on the front page. This is a problem.
 
What really annoys me, in both Google and DDG, is that even if you search "Python 3 <thing>" you get random results from 3.4, 3.5, and barely ever 3.6.
I just want the results to always point to "3", which points to the latest version, unless I search for a specific version.
 
Mm hmm, can't say I'm fond of 90% of google hits taking me to the 2 docs
While I'm rustled about version problems, I'm writing a letter to ideone to complain that they call Python 3 "Python 3" and Python 2 "Python". Is there a PEP or official trademark guideline or whatever that says to not do that? It would carry more weight than "I am a lone Internet crank and you must satisfy my whims"
 
DSM
3:24 PM
f"{greeting_vegetable}"
3
 
In[2]: f'{_}'
 
DSM
Hey, when did you join the ipython world? I don't know why I thought this, but I always thought you were a standard-repl guy.
 
No way, first thing I do in every venv is pip install ipython. I'm not a notebook user though.
 
Ah well, I sent my crank email anyway. I removed my description of Python 2 as "a slowly decaying relic" from my final draft, so I hope the result sounds even handed.
 
DSM
I only use the notebook during data analysis, when I like to mix figures and code.
 
3:29 PM
stackoverflow.com/q/48520265 dupe in comments, didn't realize until after I voted
 
3:45 PM
Any way to know if list contains any other element in a list? for example if I have list [0, 1, 1, 0, 1, 0, 2, 1, 0] how can I chack if it contains values other than 0 and 1?
 
I'd be inclined to either do any(x not in {0,1} for x in my_list) or do something cute with set.difference
 
is there already a question up for it? or can I ask my own?
 
>>> my_list = [0, 1, 1, 0, 1, 0, 2, 1, 0]
>>> has_something_other_than_zero_or_one = bool(set(my_list) - {0,1})
>>> has_something_other_than_zero_or_one
True
 
ooh clever
yeah, I'm going with that, thx!
 
(the `bool` call is unnecessary if the check is occurring inside an `if` conditional*, btw)
((*or any other boolean context))
 
3:57 PM
What other boolean contexts are there? while loops?
 
That's the one I had in mind.
 
in flask do I need to create a relationship between two tables that has a foreign key referencing it?
 
I haven't rubbed enough brain cells together on this topic to remember if there are more
 
from functools import reduce
from operator import or_
reduce(or_, my_list) > 1
 
stackoverflow.com/q/48518584 duplicate in comments
Didn't realize until someone got an MCVE out of them and posted a GitHub issue, by which point I had already voted as mcve.
 
3:59 PM
specifically for zero or one, there's a cute bitwise reduce way to do it
 
Ha! Take that, argparse! This is how I parse command line arguments:
class SomeClassWithAttributes:
    def __init__(self, a, b: bool, c):
        self.a = a
        self.b = b
        self.c = c

class Program(ui.App):
    @ui.action()
    def do_stuff(self, arg: SomeClassWithAttributes):
        assert arg.a == '5'
        assert arg.b is False
        assert arg.c == 'foobar'
        print('Success!')

sys.argv = [__file__, '-b=no', '5', '--c', 'foobar']
Program().run()  # output: Success!
 
4:12 PM
user image
9
@vaultah it was all for this
 
I wonder if he waited to be the 4th to register so it lines up perfectly...
 
wim
4:27 PM
@poke pressure (or bribery) from google
 
DSM
@davidism: nice
 
Has anyone used Flask and run a python script inside Flask?
 
I am confident that someone has, yes.
 
@davidism haha
 
4:37 PM
I have a working python code but when I run it under a Flask app it fails giving me 500 web error
Is there any limitation of running a py script in a Flask app?
 
Are you sure your environment is set up right? Try running a simple app from any flask tutorial, just to make sure that it works on your machine.
 
I know if you have any print statements in py code that breaks it
 
DSM
That seems unlikely.
 
I can run flask fine when I have a simple code
but when my script does saving and reading files etc it break
If I run script itself it works
but if I call it under a Flask app it fails
 
DSM
How are you "run[ning] it under a Flask app"? Are you calling out to it via subprocess? Importing it as a module and calling it directly? Etc.
 
4:41 PM
importing and then calling func
let me upload code
Thats the Flask app code
 
You never use ExtremeLogin, but you do use the never-defined CiscoLogin
 
and CiscoLogin is a pretty big program of multiple py file that logins to Cisco switch, run show route comman, saves the big output in text and then compares it agains user entered subnet
 
DSM
You import ExtremeLogin but refer to CiscoLogin. That seems odd.
 
What does the function subnet_compare return? A string?
 
sorry a typo
fixed
 
DSM
4:46 PM
"sorry a typo"? What's the point of giving us imaginary code which you're not actually using?
Of more use would be seeing the full traceback.
 
I am .. I am switching between Cisco and Extreme
 
garlic
 
I am CiscoLogin and ExtremeLogin
same logic but separate flask app
 
rb folks
 
It may be worth posting a question on the main site for this (but make sure to compose a nice MCVE first)
 
DSM
4:48 PM
What you are, whatever that means, isn't relevant to why your code is failing, where so far you've just said that it fails, and given no details on how. This makes it very hard to help you. I think Kevin's advice to make a full MCVE and ask it on the main site is probably sound (and you might find the bug when making the self-contained example.)
 
ok
 
It's most likely going to be a duplicate of stackoverflow.com/questions/21406057/…
 
ok will do. But the main thing I was wondering if flask limits some operations if it is run under a flask app
 
Not that I'm aware of.
 
No, Flask doesn't have a limit like that. Why would it?
 
DSM
4:50 PM
@davidism: yeah, after Kevin brought up the issue about return type it seemed likely.
 
weird because If I create a test.py on same folder and add these line, it runs fine
but not under flask
 
Run your app in debug mode and look at the actual error.
 
Indeed a curious situation. I'm quite interested in seeing a fleshed-out post for it :-)
 
I did this: app.run(debug=True)
but where would it show me errors/logs?
 
In the terminal where you're running it, just like any other code.
This is getting silly.
 
4:53 PM
hmm .. it did not show anything when I last used it
 
You're basically making us slowly play 20 questions with you. See MCVE.
 
Is it bigger than a loaf of bread?
 
thats the point of a chat but ok lol
 
recbg, maybe cbgrbrb
 
Do we perchance have a post that answers why attributes can't be set on methods?
>>> Class.func.foo = 0
>>> Class().func.foo = 0
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'method' object has no attribute 'foo'
 
4:55 PM
@Damon actually, that's not the point of chat. Please read our room rules: sopython.com/chatroom
 
ok ...
 
wim
@Rawing on bound methods
 
Chat can be used as a sort of iterative interactive collaborative debugging session, but you've got to meet the prerequisites e.g. being forthcoming in response to questions, having a solid grasp of local debugging tools, being able to present diagnostic information in a compact fashion, etc etc etc.
It's a skill that people often forget is a skill, much like composing a good google query
 
@Damon Note that this is not a random support chat. We are happy to help, but we are doing all this on our free time because we want to. So you should really accommodate us with trying to go out of your way to make it easy for us to help you. That means that you should attempt to solve the problem yourself first and give us all the information we need to understand your problem and what you have already tried.
 
DSM
I wonder if I can convince NumberFirm that working on "Debugging in Python" counts as my volunteer time..
 
wim
5:00 PM
@Rawing I've actually never noticed this before
 
@wim Unbound methods don't exist anymore, do they?
 
wim
True, they're just called "functions"
but I still think of the function on a class as a method
and the function in a module as a function
 
I am ok with python but very new to flask. I was not seeing anything on terminal so was wandering maybe flask shows it somewhere else
but I get your point
 
@wim If you want to write an answer, here's the question
 
I think "Where do flask errors get displayed?" is a fine question, really. Shows a willingness to learn how to fish, as it were.
(although if the answer is something self-evident after a couple minutes of experimentation, that's less fine. I don't know how self-evident it is, as I've done thirty minutes of Flask development in the last year)
 
5:06 PM
when you run flask in debug mode it already prints a handful of messages for you
 
It does not show anything for me "app.run(debug=True)"
I will do some more google searching
 
wim
are you running directly at the terminal, or in some weird IDE of some sort
 
Currently working with django and via ajax I am sending every 0.5 secs request to the server, any recommendations what I should use for making it asynchron?
 
terminal, my ubuntu has no GUI
all CLI
 
wim
@Rawing thx. ugh, it's gross when people try to use decorators for this kind of stuff.
 
5:11 PM
Is it? What's the better alternative?
 
not asynchron, mean different sockets. Anything better out there than dj-channels?
 
There are duplicates for "how to run flask in debug mode" and "where are my flask errors"
 
5:30 PM
c-c-c-c-aaaabbaaaage breaaaker
\o room 6 family
 
cbg
 
cbg
 
This question is a great example how not creating an Mcve can easily confuse people. OP’s example uses reflection and whatnot to create a weird example that causes the error. But actually, the error already appears just by replacing that whole junk with two lines. If OP tried to actively remove code before posting it, they might have discovered that on their own and found something to google for.
 
way too much code, won't read.
 
something something haters
 
5:32 PM
yes
 
Secretly, I like CVEs, because they scare off fast-gunners, leaving me to write an answer in peace
 
respect
 
"But don't you think it's selfish to favor questions that benefit you personally while harming the rest of the community?" Yes. Yes it is.
 
You could always edit them afterwards to be better questions :P
 
But I've already gotten my points by then, and like the mighty lion I must nap after feasting
 
DSM
5:48 PM
I just finished an individual pizza from the cafeteria. I like the idea that I'm tired because I'm like a mighty lion.
 
So very mighty.
 
wim
@Rawing running your code in a profiler will aggregate info about number of calls etc. I don't like to put that stuff into the actual code itself.
 
@DSM What is an “individual pizza”? Are there communal pizzas too?
 
DSM
@poke: I suppressed "-size" there. As in, a pizza appropriately sized for one man. Unless you're very hungry, a large pizza at the cafeteria is definitely intended for communal use..
 

« first day (2663 days earlier)      last day (2284 days later) »