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.
 
  • Locked thread
Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

Hammerite posted:

I am aware now, after reading his second post, that he is just trying to retrieve arbitrary elements from a list of their offsets. When I responded to his first post, I misunderstood what he wanted, because he used the term "slice". In his second post, he used the term "slice" again, and I presumed that on that occasion he had used the term in that way intentionally and was asking me a follow-up question about slicing.

I for one am glad you answerd the "wrong" question, as I learned something from it. And while it is important to point out when an answer is not correct, or to the wrong question, it is too bad people are frequently more harsh about it than they need be. (I am guilty of this as well, sadly)

Adbot
ADBOT LOVES YOU

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

QuarkJets posted:

My girlfriend is interested in learning more web development skills. Maintaining a web site is a small facet of her job, so it actually does have some applicability to what she's doing. For instance, she knows how to use CSS and javascript. She knows that I've been using Python for a long time, and she has asked me if Python is a useful language to learn for web development purposes. I wasn't sure what to tell her; I've never done any web stuff.

Searching around on the web gives links to people talking about how awesome django is as a web framework, but I don't really understand what django does. Is it only useful for creating web applications with forms and the like or can it also just be used to make nice-looking web sites in a relatively easy way?

"It depends"

I'm sure you know this already, but for the sake of clarity: To make nice looking websites, you don't need any languages other than HTML / CSS.... To make nice looking database driven websites, you'll need some sort of server language.

Python is one of them, and like all the other languages one could use, there are a bunch of MVC frameworks that help you do common tasks like url routing, validating form input, getting data from the DB, displaying data in templates, etc. Two of the biggies in python-land are Flask and Django. They are both good, have different "philosophies".

That said, depending on her needs, something like WordPress (shudder) might be better than diving into a development framework.

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

ahmeni posted:

Is there something decent as a 2d game library these days? There's a ton of abandoned half-finished libraries. What I know about so far:

cocos2d - Nice, quick and multi platform, full of great stuff but the documentation is almost non-existent for the python edition, just about everything I've been able to find is for the iOS version. If I could find a decent resource for it I'd use it in a heartbeat.

With Apple introducing it's own 2d game framework for iOS, cocos2d for iOS is all but dead. I know they had a big push to make javascript it's primary focus, so maybe that will keep it around, and the tutorials may all start switching to JS... :iiam:

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

duck monster posted:

That I doubt. Cocos2d for ios has the lionshare of the market, is conceptually multiplatform via cocos2s-x and its html5 spin-off and has zynga as the 700lb gorilla backing it.

Apple could make a big impact by bringing scene kit across to the ipad which would pull the rug out from cocos2d feet by delivering proper 3d, (There is cocos3d but its a bit of a mess and doesnt support shaders making it pretty ancient and lovely), but at the moment gamekit is the minority platform for the iphone right now. Its not widely used, hasn't the tooling cocos2d has, nor is it as capable. Or as easy actually.

Cocos2d python is very nice by the way.

Zynga is dying fast,but that's besides the point. For iOS (again, I'm being specific to iOS here) cocos2D is going to all but vanish. This does not mean cocos2D is going away. I was pointing out that it's heavy focus on iOS will be going away most likely, as that was one of the original poster's concerns: that so much of it's tutorials / samples were iOS related. I'm simply pointing out that the focus of cocos2D will shift away from iOS, and has been slowly for a little while, but that trend will accelerate since Apple's new 2D game API will likely be getting a large dev mind-share in iOS-land.

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

Misogynist posted:

Most of the dynamic content (polls, visualizations, etc.) on the Washington Post's website is also Django. They've got a pile of extensions on their GitHub account.

I also believe these little sites called "Pinterest" and "Instagram" are Django / python apps.

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice
Speaking of SQLAlchemy...

I am about to start an app in python that will be calling stored procedures on an MSSQL database. After looking around a bit, I think SQLAlchemy is probably the right way to connect / call, but I'd love to hear any alternate solutions or gotchas if anyone has done this before.

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

Pollyanna posted:

Disregard previous post! Got something working, finally. Go check out How are my stocks doing? and follow the instructions there for great fun!

By the way, I mention it there, but I want the url to be (for example) /stocks?symbol=AAPL and that will return the stock chart for AAPL. How do I do this in Flask?

:google: "Python flask get URL variables value" and you will see many ways.

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

John DiFool posted:

Yes, hi mr. duck monster what is your question sir? You must please with asking the question.

Someday we will be able to harness Duck Monster's impotent rage into a source of energy for the entire planet.

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

Dominoes posted:

I'm looking for advice on how to store database information for a Django web app on RHCloud. I'm uploading raw text info of temporary flying restrictions, and want to store and reference them. Columns would be something like this: "id, start date, end date, category, min alt, max alt" etc. There would probably be a few thousand entries.

The basic program's done; it parses the text from a webpage, sorts it out with regex, generates the required files etc. I want to store the data in a database to make sure that older info that isn't expired is still used, even if it's no longer present in the uploaded text.

Should I try Django's models system? It uses databases, but the tutorials I've read are mostly about using it for an admin page, storing user logins etc. This is a webapp so it can run on work computers (RHCloud is miraculously not blocked), and interface with GMaps' JS API. I'm not sure the models system would be appropriate.

Should I do the database manually? I've used sqlite before. I've read that you shouldn't use it for production use, but this would only be used by 1 person at a time, so it would probably work.

You can write your own ModelManager to handle hooking up the ORM to a remote DB. We are in the process of writing a Django app that uses a custom ModelManager coupled with SQLAlchemy to use a (*shudder*) Azure Cloud MSSQL store for our data.

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

lufty posted:

Python code:
def RollRepeat(): #inserts a loop into the code allowing repeatiblity of the dice roller
    UserInput = input("Do you want to try again? Type Yes or No.\n")
    if UserInput.lower() in ("No", "no", "n"):
        exit(0) #this exits the program
    elif UserInput.lower() in ("Yes", "yes", "y"): 
        return True
    else:
        print("Not a valid input.")
        return False
carryon = True
while carryon: #completes the loop
    RollFunc()
    carryon = RollRepeat()

invalidcarry = False
while invalidcarry is False:
    invalidcarry = RollRepeat()
what would the correct coding be to ensure a correct error message and return to "Do you want to try again?"

Assuming I understand what you are asking, this will prompt the user if they want to continue after an error:

Python code:
  1 def roll_func():
  2     print("Buttes!")
  3 
  4 
  5 def roll_repeat():
  6     user_input = raw_input("Do you want to try again? Type Yes or No.\n")
  7     if user_input.lower() in ("no", "n"):
  8         print("Well screw you then!")
  9         exit(0)  # this exits the program
 10     elif user_input.lower() in ("yes", "y"):
 11         return True
 12     else:
 13         print("Not a valid input.")
 14         return roll_repeat()  # <- THIS IS DIFFERENT
 15 
 16 carryon = True
 17 while carryon:  # completes the loop
 18     roll_func()
 19     carryon = roll_repeat()
You simply call the function that asks them if they want to continue again if you didn't understand the input.

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

Ahz posted:

I asked this in Djagno thread, but it should probably go here:

Does anyone know the best go-to library or whatever to generate custom QR codes?

I'm looking to generate and then store the GIF or whatever they create as a binary in postgres.

I used this: https://pypi.python.org/pypi/qrcode with much success in a project. I have no idea if it's the "Best" but it generated QR codes really fast and didn't blow up, and somebody as dumb as me could figure out how to use it.

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice
As was posted just above: http://www.greenteapress.com/thinkpython/

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

Literally Elvis posted:

I'm writing a small django app thing and I need to set a few GET parameters to None if they're not in the URL, is it better to do:

Python code:
args["term"] = request.GET["t"] if request.GET["t"] else None
or
Python code:
if request.GET["t"]:
    args["term"] = request.GET["t"]
I like the first one since I have to do it a few times, but I don't want to give any more reasons for someone to scoff at my code than they normally do.

I believe you want to do something like so:

Python code:
t= request.GET.get('t', None)
You could then make a loop of the various params you are looking for and assign them to a dict:

Python code:
params = {} 
expected_params = ['t','a','b', 'z']
for p in expected_params:
    params[p] = request.GET.get(p, None)

Lumpy fucked around with this message at 17:37 on Dec 31, 2014

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

Thermopyle posted:


Of the set of all IDE/editors that people talk about liking in this thread, and without having done any sort of count, my gut tells me that PyCharm probably gets brought up the most.

Serious question: is PyCharm worth allowing Java to be installed on my machine? I've kept it off of all my computers for the last 6+ years due to :tinfoil: security paranoia. I use MacVim and love it, but all the folks loving PyCharm had me wanting to try it, but then Java.

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

dantheman650 posted:

This is something I'll check into. I thought I had remembered seeing the bug upon a fresh run of the program but perhaps I'm remembering incorrectly. I'll report back soon, thanks!

Edit: Instead of creating a new Ship object upon restarting the game, I just reset the original Ship object's parameters and that fixed it. Thanks so much for pointing me in the right direction! Everything appears to be running smoothly now.


Thanks for the comments! This is completely new stuff to me, and I'm a little ashamed to admit I don't even know exactly what testing means. I've never used a debugger or anything like that before. Are there any recommended beginner resources for TDD?

In addition to the testing goat recommended above, get a copy of Kent Beck's: Test Driven Development by Example. It sold me on the virtues of TDD in addition to a nice intro into the practice.

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice
I searched the thread a bit and didn't see any recent discussion on it, so I shall ask about pulling text from PDF documents. I found a lot of packages that do this, but would love to hear any personal experience with them if people have any. I don't need any sort of images or charts from the docs, just plain old text. Thanks!

Adbot
ADBOT LOVES YOU

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

Dren posted:

it will work with varying degrees of success. Depends on the PDF. Could be the pdf you think is text is actually a bunch of images, in which case you'll get nothing. Could be there is some formatting that the text extractor will inconsistently be tripped up by. pdf is a crazy format.


onionradish posted:

Echoing Dren's response. I've used the pdfminer library -- actually the pdf2txt.py CLI script that comes with it -- to extract text from short document PDFs. The order of various text blocks is often mixed up if there is multi-column content, captions, headings or headers/footers. Line breaks are often "hard breaks" requiring re-wrapping of paragraph text. Almost all of that has to do with the PDF format itself. The CLI script has some parameters that can help rejoin blocks of text.

If you're dealing with relatively consistent types of PDFs, especially if they're short, the cleanup isn't too bad -- it's simpler than cleanup after OCR, for example -- but it all depends on the PDF.

Thanks for your responses. I know that PDFs are no fun, and that I can only strive for a "least worst" solution, but anything better than manually copying and pasting thousands of docs is an improvement!

  • Locked thread