Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Master_Odin
Apr 15, 2010

My spear never misses its mark...

ladies
It's not necessarily "bad" for what it does, but it does mean that Python ships with a Tcl interpreter and some other stuff to make it work which causes some amount of explosion in the building python. This isn't a great thing given how little tkinter is really used out in the real world.

Ghost of Reagan Past posted:

But yes just rip off the Python 2 bandaid. Now that supervisor 4 has Python 3 support there is basically zero excuse for it. Your lovely legacy application needs to get ported to Python 3, and that's all there is to it.
Except that they continue support of Python 2.7 in supervisor 4 giving people an easier time of just not migrating. I hope in the next couple of versions they drop that and just focus on Python 3. Major libraries that keep supporting Python 2 will continue to allow people to keep that bandaid on that much longer.

Adbot
ADBOT LOVES YOU

NinpoEspiritoSanto
Oct 22, 2013




I find it hard to get worked up over libraries maintaining support for 2.7 while 2.7 is still supported by Python core.

Ghost of Reagan Past
Oct 7, 2003

rock and roll fun

the yeti posted:

Is tkinter really that bad? I ask this relatively innocently--I've seen a small example and it seemed pretty clumsy, but I have almost no experience with Python GUIs besides learning PySimpleGUI to refactor said small example.
There's nothing really awful about it but it's just not where the world is nowadays -- if you're going to build a GUI application with Python in 2019 you're probably better off just using Flask and building a web application, or some better, more modern libraries. Maintaining tkinter support for no real reason means that you add build complexities and bloat. Brown picked it out as an example, but there's a bunch down there in the stdlib. Luckily there's upcoming effort to remove and deprecate some more useless packages (macpath, holy poo poo!), but I think a stronger culling and a focus on rationalizing the low-level APIs is probably the path forward.

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

There's lots of stuff in the stdlib with inconsistent APIs or just simple stuff like not following PEP-8. Ironing out a bunch of that would help make the stdlib feel less icky. There's a lot of low hanging fruit here, but it just requires someone to take ownership and get it done.

Something I use constantly is the logging package. getLogger...really?

Hughmoris
Apr 21, 2007
Let's go to the abyss!

Thermopyle posted:

I haven't read your posts on this subject real closely, but look into xpath maybe?

Thanks, I'll look in to that!

QuarkJets
Sep 8, 2008

the yeti posted:

Is tkinter really that bad? I ask this relatively innocently--I've seen a small example and it seemed pretty clumsy, but I have almost no experience with Python GUIs besides learning PySimpleGUI to refactor said small example.

It's pretty bad, in that the options are too simple and clunky to make really nice interfaces. But it's good enough for simple ones. But I agree that it shouldn't be part of core Python, it should be a separate module.

Or another example, getopt vs optparse vs argparse. We don't really need 3 argument parsing modules in stdlib, and 1 of them (getopt) is even kind of bad. Even the python docs for getopt and optparse point out that you should be using argparse, instead.

The getopt doc page even has an argparse example, to basically say "look at how much cleaner and better this is, please don't actually use getopt". But so long as it exists in stdlib, newer people will continue stumbling upon getopt and then using it.

dougdrums
Feb 25, 2005
CLIENT REQUESTED ELECTRONIC FUNDING RECEIPT (FUNDS NOW)
You can always build python without tkinter, but that just makes using/deploying python more complicated in general.

Empress Brosephine
Mar 31, 2012

by Jeffrey of YOSPOS
Hello I’m new to Python but I want to jump thirty steps ahead. I developed the code for a little program I can use for work (although perhaps Python wasn’t the best language for it, it’s a program that asks you how many tickets of each type do you want then spits out a price ) but I want to make a decent UI for it that anyone could use. Where would I work towards next?

Thanks

Ghost of Reagan Past
Oct 7, 2003

rock and roll fun

Empress Brosephine posted:

Hello I’m new to Python but I want to jump thirty steps ahead. I developed the code for a little program I can use for work (although perhaps Python wasn’t the best language for it, it’s a program that asks you how many tickets of each type do you want then spits out a price ) but I want to make a decent UI for it that anyone could use. Where would I work towards next?

Thanks
My standard suggestion is build it as a web app. I always recommend Flask for this. You'll have to build HTML templates, but I've generally found that HTML+CSS+Javascript is better than most other GUI solutions like Qt or (as we've been talking about) Tkinter.

Empress Brosephine
Mar 31, 2012

by Jeffrey of YOSPOS
Thanks for that, I already know HTML and CSS so it shouldn't be that much of a stretch :)

the yeti
Mar 29, 2008

memento disco



Ghost of Reagan Past posted:

My standard suggestion is build it as a web app. I always recommend Flask for this. You'll have to build HTML templates, but I've generally found that HTML+CSS+Javascript is better than most other GUI solutions like Qt or (as we've been talking about) Tkinter.

Is there a way to organize a Flask app that doesn't involve hypothetical end users either relying on the developer to host the app or arranging their own server?

Master_Odin
Apr 15, 2010

My spear never misses its mark...

ladies

the yeti posted:

Is there a way to organize a Flask app that doesn't involve hypothetical end users either relying on the developer to host the app or arranging their own server?
Use electron?

Empress Brosephine
Mar 31, 2012

by Jeffrey of YOSPOS
I think Flask is way out of my league skills wise now...I’ve only done If statements and for loops so far

Ghost of Reagan Past
Oct 7, 2003

rock and roll fun

Empress Brosephine posted:

I think Flask is way out of my league skills wise now...I’ve only done If statements and for loops so far

Eh you'll be fine, just dive in. Flask is a lot of magic but if you follow the instructions you can build websites quite quickly. Python's an easy language, so just build poo poo even if it's out of your league.

cinci zoo sniper
Mar 15, 2013




Dominoes posted:

Pendulum, like moment and arrow, has no discrete Date and Time types.

Unfortunately, although it does, to be fair, position itself just as a datetime replacement.

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

Empress Brosephine posted:

I think Flask is way out of my league skills wise now...I’ve only done If statements and for loops so far

Building stuff out of your league is how you get them in your league!

Empress Brosephine
Mar 31, 2012

by Jeffrey of YOSPOS
Yeah that’s true...I’ll try it out thanks for the pep talk goons :3

LuckySevens
Feb 16, 2004

fear not failure, fear only the limitations of our dreams

Hi, I’m thinking about starting a game project and I’m wondering if some kind people would give me their 2 cents on this plan:

The game itself is a simple auction game, where players “invest” in a portfolio of stocks, which give the right to someone for an income stream. The game then totals up this “income stream” using a bunch of silly metrics across trending twitter topics and tweets. This money is then returned to the player’s account at either a gain or a loss. Cash balance is just points, with stock market-like properties, except unlike the stock market, players must reinvest once a week. They will also have opportunities to invest in silly side games during the week, using the same system, but it is not mandatory. There are a lot more details but that’s the jist.

I must emphasise, this is not a game for real money and will never be. It’s just among friends, like a silly Fantasy sports offshoot. Testing on the fly is ok, so long as it’s accessible.

  • Using Flask with Pusher managing all the accounts and games in progress
  • Building a live table inside Pusher channels for data collection
  • Charts will be available to players, with stock market type information about the income/value. Plotly was recommended
  • Players can see/download information on other players decisions, and view leaderboards with aggregate scores/statistics based on decisions
  • Realtime updating would be nice since it is technically an auction with bids, but will not need to worry about bid sniping strategies, as there’s only one submission per week per players
  • The submission for stock purchases (Monday morning, same time every week) can be tweaked, and a decision templating system will be necessary
  • Auction process itself can be batched. Processing time to determine order success can be hours. Persistent profile updating not necessary at this stage
  • To calculate the results data, all tweets from around 500 accounts will be collected using a scraping system, as well as hashtags trends. An equation determines “points” i.e stock returns
  • At the end of the week, at a set time (likely Sunday evening), the results are tallied, and account balances adjusted accordingly. The game resets with a fresh balance equivalent to money remaining

The game will max out at 30 participants at first. Unlikely to be used more than a few times a week.

I don’t mind paying for useful services/packages, but this game will not be earning any money, so within reason.

May need light media like profile photos, photo descriptions of stocks etc, but doesn't need to be overly polished, just useable.

I am an economist by trade who is familiar with python. I use jupyter/numpy frequently. I’ve set up a django login before with a dashboard. So this project is a little outside my norm, but it really seems like I could get a bare bones project up and running with enough time. Any feedback appreciated!

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

That's all technically feasible and both Flask and Django are fine choices.

There's nothing you'll have to or need to pay for except for maybe somewhere to host your code.

General_Failure
Apr 17, 2005
I have been having a gilded poo poo of a time installing things with pip the last couple of days on everything. Pretty much anything has (PEP 5nn) after the module name it's trying to install, before it just fails saying something about no backend. The number varies but it seems to be in the 10s to 20s. What's changed recently. I can't find anything on it.

e:

From my pinebook, trying to install scipy in a python3 venv.
Unfortunately it took a very long time to reach this conclusion, and when it finally did, the error was far longer than the lxterminal buffer.
I've encountered similar on my Orange Pi 3 and Orange Pi zero running Armbian, and on my RPi Zero running Raspbian stretch. For some reason they are getting all worked up, trying to build wheels, and failing because of this PEP error.
code:
Failed to build scipy
ERROR: Could not build wheels for scipy which use PEP 517 and cannot be installed directly

General_Failure fucked around with this message at 00:16 on May 28, 2019

Hughmoris
Apr 21, 2007
Let's go to the abyss!
Is there any recommended reading for thinking and designing your programs in an OOP style?

I understand the basics of writing OOP, and I can walk through someone's OOP-styled program and understand what's going on. However, when it comes to designing my own programs, I naturally go to procedural or functional style. Learning more OOP seems like it would be beneficial since the majority of people write their python apps that way.

a dingus
Mar 22, 2008

Rhetorical questions only
Fun Shoe
That is a great question. I wonder the same thing. Like when I write a program that sends an email... do I split the code that sends an email into another object? Do I write the code in a functional style and then make all of the functions a method in my class?

duck monster
Dec 15, 2004

dougdrums posted:

Oh and if you want to match on regex or an expression, you can filter with a comprehension over the dict then reduce.

Else Statement Considered Harmful

When choosing between idiomatic and clever, always chose idiomatic. The Else block is a perfectly natural part of code thats been around since the earliest days of both imperative and functional coding.
code:
 (if (expression)                ; if-part
       (message "Its true!") ; then-part
       (message "It lies!))   ; else
Hell, the latest fancy academic languages like Haskell build it right into the type system.

dougdrums
Feb 25, 2005
CLIENT REQUESTED ELECTRONIC FUNDING RECEIPT (FUNDS NOW)

duck monster posted:

Hell, the latest fancy academic languages like Haskell build it right into the type system.

I'm not sure what you mean? If you are referring to case expressions, any form of matching in haskell reduces into a case expression, but they're expressions. I'm not sure that there are any special rules for inference of case expressions, besides what can be derived from the semantics of case itself. You can't really compare if-elseif-else or cases in imperative languages to matching in functional languages (or the conditional operator), because the former are statements, and the latter are expressions.

Matching with a dict in python is just the functional perspective, in that sense.

LuckySevens
Feb 16, 2004

fear not failure, fear only the limitations of our dreams

Thermopyle posted:

That's all technically feasible and both Flask and Django are fine choices.

There's nothing you'll have to or need to pay for except for maybe somewhere to host your code.

Thanks for reading, no doubt I'll be back with more questions once I get into the thick of it.

Boris Galerkin
Dec 17, 2011

I don't understand why I can't harass people online. Seriously, somebody please explain why I shouldn't be allowed to stalk others on social media!
For an application (I'm thinking of things like flask, where you create a single app instance to do everything/hold state info), does it make sense to create one logger at the application level or still to just create them per module as needed?

code:
# in myapp.py
class App:
    logger = logging.getLogger('myapp')

# in mymodule.py
def something_awful(app):
    app.logger.info('oh no')
or

code:
# in myapp.py
class App:
    pass

# in mymodule.py
logger = logging.getLogger(__name__)
def something_awful(app):
    logger.info('oh no')

CarForumPoster
Jun 26, 2013

⚡POWER⚡
Going to start my first django project this week. If I like pycharm, is it worth getting the professional version over community because of the wed development related features? If this project goes well I expect to be using it daily for several weeks at least.

Dominoes
Sep 20, 2007

Yes.

SurgicalOntologist
Jun 17, 2004

Boris Galerkin posted:

For an application (I'm thinking of things like flask, where you create a single app instance to do everything/hold state info), does it make sense to create one logger at the application level or still to just create them per module as needed?

code:
# in myapp.py
class App:
    logger = logging.getLogger('myapp')

# in mymodule.py
def something_awful(app):
    app.logger.info('oh no')
or

code:
# in myapp.py
class App:
    pass

# in mymodule.py
logger = logging.getLogger(__name__)
def something_awful(app):
    logger.info('oh no')

In my experience there's never any need to be passing logger objects around. Because of their namespacing magic, getLogger('a.b') will grab the same logger regardless of where it's run from, and it will inherit from getLogger('a') regardless of the relationship between the files.

What I've done that works well is always do getLogger(__name__) for logging messages, and for configuration you always of changing the settings of the master logger instead of individual loggers. In other words, you can still make them all behave the same way, or not, as you prefer. On the other hand, if you are always using the same logger, you lose one of those options.

Phobeste
Apr 9, 2006

never, like, count out Touchdown Tom, man
Yeah I’d always make loggers for a module using __name__ because if you have static utility functions, whether done as free functions or as staticmethod or classmethod, you won’t necessarily have access to instance attribute loggers. Now you might go ahead and make instance loggers that are children of the module logger, but to make the namespacing work properly so you can do configuration at the top of the hierarchy a module level logger should probably be in there somewhere

KICK BAMA KICK
Mar 2, 2009

I find myself configuring a logger named like 'project' at the start and then each module gets its child logger 'project.' + __name__; just using the root logger and say, setting the level to DEBUG, will apply that to library code using loggers as well.

SurgicalOntologist
Jun 17, 2004

KICK BAMA KICK posted:

I find myself configuring a logger named like 'project' at the start and then each module gets its child logger 'project.' + __name__; just using the root logger and say, setting the level to DEBUG, will apply that to library code using loggers as well.

Well, __name__ includes the module hierarchy so as long as you're working in a package you should still have a package root separate from the global root. Unless you just have a loose connection of scripts, or a project consisting of multiple packages (without a parent package), then yeah you may need to do string concatenation.

punished milkman
Dec 5, 2018

would have won

CarForumPoster posted:

Going to start my first django project this week. If I like pycharm, is it worth getting the professional version over community because of the wed development related features? If this project goes well I expect to be using it daily for several weeks at least.

If you can afford it then yes absolutely

KICK BAMA KICK
Mar 2, 2009

SurgicalOntologist posted:

or a project consisting of multiple packages (without a parent package)
Yeah it was this, main.py by itself next to all the package directories, never even thought about that.

SurgicalOntologist
Jun 17, 2004

Weird. Put an __init__.py there and make a containing package IMO.

Phobeste
Apr 9, 2006

never, like, count out Touchdown Tom, man
Depending how you run it your entrypoint might have a __name__ of '__main__' and not get caught by configurations you apply to your package root just fyi.

PierreTheMime
Dec 9, 2004

Hero of hormagaunts everywhere!
Buglord
Hopefully quick Python installation question: I've installed 3.7.3 onto a Windows server, confirmed the path is set, and restarted it. I can now execute commands from command line, PowerShell, etc. locally just fine, but the same commands produce a "Can't find a default Python" error if I attempt to execute them as a remote batch job.

The remote user has administrative rights, any ideas of what I might be missing?

Proteus Jones
Feb 28, 2013



PierreTheMime posted:

Hopefully quick Python installation question: I've installed 3.7.3 onto a Windows server, confirmed the path is set, and restarted it. I can now execute commands from command line, PowerShell, etc. locally just fine, but the same commands produce a "Can't find a default Python" error if I attempt to execute them as a remote batch job.

The remote user has administrative rights, any ideas of what I might be missing?

The only thing I can think of off the top of my head the $PATH for python is not being passed to the remote user an environment setting.

What happens when you execute with the full pathname to python in the script?

PierreTheMime
Dec 9, 2004

Hero of hormagaunts everywhere!
Buglord

Proteus Jones posted:

The only thing I can think of off the top of my head the $PATH for python is not being passed to the remote user an environment setting.

What happens when you execute with the full pathname to python in the script?

If I run it directly it works fine. If I try specifying the version, the py launcher helpfully informs me that it can't detect Python being installed.

Test script (PyTest.py just runs print("test")):
code:
& 'C:\Program Files (x86)\Python3.7.3\python' "\\filepath\PyTest.py"
py -3.7 "\\filepath\PyTest.py"
Result:
code:
test
Installed Pythons found by C:\Windows\py.exe Launcher for Windows
No Installed Pythons Found!

Requested Python version (3.7) not installed, use -0 for available pythons
Python 3.7 not found!
Again, run locally just "py" works, but "py -3.7" works as well. I can just force it to do the full path every time, but that seems really silly and denies me the ability to execute code from my automation platform directly.

Adbot
ADBOT LOVES YOU

Business
Feb 6, 2007

The subject of pickling came up earlier and I am new to the whole idea of serialization so I wanted to check if what I'm doing makes sense. I am working with spaCy for NLP and I wanted to save large Doc objects (spacy thing that contains lots of NLP data for text(s)) on the backend of my django app. Here's what I'm thinking: a user uploads a text and the backend processes it and saves it as a .pickle so they don't have to re-process the text every time they want to use it. When the user wants to do something to the previously uploaded text, I have the backend open up the saved pickle, search through it, and serve that data to the user. The pickle file seems gigantic to me (600 kb text file to 17 mb .pickle) so I'm worried I'm going about this the wrong way.

Is this an appropriate use case? Eventually I want to add users and allow them to save processed text files. Do I store those pickle objects as fields in a database or is that a Bad Way to do things?

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply