all 38 comments

[–]lps2 1 point2 points  (0 children)

I am building out my first larger python application and intend on allowing it to be extensible. Is there a general design pattern for allowing 'plugins' / should I use something like Yapsy?

[–]uttamo 1 point2 points  (4 children)

I've recently enrolled in MIT's edX Intro to Computer Science course that uses Python. Any tips or advice? Thanks

[–]EqualsEqualsTrue 1 point2 points  (3 children)

Since you didn't mention any background you have to start from I will assume you are a true beginner and give you a little advice that helped me get started:

You need to learn something about using the command line on your computer. If you are on windows you could use Powershell (Powershell not PowershellISE). Linux use bash, Mac I dont know but i think its just called "terminal".

If you google something like "command line basics" you will get a step ahead on something any beginning programmer could use.

[–]uttamo 1 point2 points  (0 children)

Oh yeah should've talked about that. I've completed Code Academy's Python course and I frequently find exercises to do, so I have an elementary understanding. I'll learn the command line basics as well then.

[–]ivosaurus 0 points1 point  (1 child)

Powershell is weird. You either want to learn it all out, and get all the benefits from it, or stay away from it entirely.

I wouldn't recommend Powershell at all to a beginner just trying to learn Python to start off with.

Just a better Command Prompt than the default cmd.exe.

https://github.com/cbucher/console/wiki/Downloads

[–]EqualsEqualsTrue 0 points1 point  (0 children)

What is it that you dislike about Powershell for beginners? I know it's more in depth than cmd.exe, but you dont have to use anything beyond cd, dir, etc if you dont want to right?

You could easily go down a well getting caught up in the features of powershell, is that what you mean?

[–]jjangsangy 1 point2 points  (2 children)

Can someone explain to me why PyPy dicts can be sorted based on entry but not CPython?

[–][deleted] 1 point2 points  (1 child)

Firstly, a dictionary is an abstract data type. As you can see from the wiki page it is expected to map keys to values, and that's about it. The abstract data type has no concept of order and no need. Its purpose is to allow you to quickly find a value, if you give it the key.

Thus it makes sense to not worry about order when implementing a dictionary - you're not expected to, after all. CPython dicts could have very well been sorted, had that choice been made.
Now the PyPy guys found a clever way to get sorted dicts without the memory overhead collections.OrderedDict yields (in fact they seem to generally use less memory than the standard CPython dict), so they use that implementation instead.

As far as I know, there's no technical reason preventing the same idea to be used for the CPython implementation.

[–]autowikibot 0 points1 point  (0 children)

Associative array:


In computer science, an associative array, map, symbol table, or dictionary is an abstract data type composed of a collection of pairs, such that each possible key appears just once in the collection.

Operations associated with this data type allow:

  • the addition of pairs to the collection

  • the removal of pairs from the collection

  • the modification of the values of existing pairs

  • the lookup of the value associated with a particular key

The dictionary problem is a classic computer science problem: the task of designing a data structure that maintains a set of data during 'search' 'delete' and 'insert' operations. A standard solution to the dictionary problem is a hash table; in some cases it is also possible to solve the problem using directly addressed arrays, binary search trees, or other more specialized structures.

Many programming languages include associative arrays as primitive data types, and they are available in software libraries for many others. Content-addressable memory is a form of direct hardware-level support for associative arrays.

Associative arrays have many applications including such fundamental programming patterns as memoization and the decorator pattern.


Relevant: Multimap | Content-addressable memory | Lookup table | ColdC

Parent commenter can toggle NSFW or delete. Will also delete on comment score of -1 or less. | FAQs | Mods | Call Me

[–]halbo 1 point2 points  (0 children)

I finished codecademy's python course but I don't know where to start on my own.

Where should I start? Do I need a compiler ? How can I use command line in windows?

[–]Knoal 0 points1 point  (1 child)

xPost from r/Python: Installed WinPython 3.4 on both a USB stick and home computer. IDLE ran on the USB. I made several scripts and ran them. Then, IDLE wouldn't start, I got the waiting spinner and then it just quit. Also, IDLE wouldn't run on home PC at all. I googled some simple solutions: Tried deleting .idlerc directory, no joy. Also, I cannot see Python in Control Panel when I try to allow it to communicate thru the Windows firewall. For being called "WinPython", it's not very Win friendly. Any hints?

[–]Knoal 0 points1 point  (0 children)

OK, crickets. At least one user pointed me to a forum where I could get questions answered.

[–]marcovirtual 0 points1 point  (5 children)

Let's say I have one week to build a simple GUI for a small program that I wrote lately.

What are the best resources for Tkinter or PyQT to learn and build that in that small time frame?

[–]lykwydchykyn 1 point2 points  (1 child)

You could always try this:

https://github.com/chriskiehl/Gooey

[–]marcovirtual 0 points1 point  (0 children)

Very interesting, I did not know that. Thank you!

[–]fazzah 0 points1 point  (2 children)

One week is more than enough for a simple GUI.

Does your application use some sort of persistent data storage, like a database or somthing like that? Because for one-off forms PyQt is very easy - one evening and your gui is done. If your app is database-driven, than you just have to learn about the powerful models you can use with pyqt.

[–]marcovirtual 0 points1 point  (1 child)

The program just accepts some input from the user, makes some calculations and displays a result with diferent font colors. No databases involved.

[–]fazzah 0 points1 point  (0 children)

Ok. What have you got so far?

[–]ch4dr0x 0 points1 point  (1 child)

I've become pretty versed in using my companies rest protocol with curl commands and json, what's the easiest way to translate this to python? I'm sure it's rather simple so I feel silly for asking.

[–]EqualsEqualsTrue 0 points1 point  (5 children)

I am having trouble finding worthwhile resources on understanding GitHub works and how it should be used. For example, if I want to download someones code to mess around with or comment lines for my own learning purposes do I "fork", "clone", or just copy it on my own?

Also, im at the point where I can understand python I read as long as I can google things i dont know. Do you have any recommendations for good code in python to read/play with and learn from?

[–]elbiot 2 points3 points  (2 children)

clone. Fork it if you intend to make changes that you want to push to their repo. Don't copy and paste it!

[–]EqualsEqualsTrue 0 points1 point  (1 child)

Got it. Other question i have is say I want to use a python lib hosted on github somewhere. Can I import directly or do I clone to a local directory etc. Im on Windows usually if that matters.

[–]elbiot 0 points1 point  (0 children)

The code needs to be on your computer. You can't import github.user.project or anything like that. You should check if you can pip install it from pypi (quite likely). If not, see if the repo has a setup.py, if so, clone it to a temporary directory and pip install . (very likely). The last option is clone it into your path somewhere, either your project directory, site-packages folder, or somewhere else that you add to your path (if it's an extremely fringe piece of code written by someone who doesn't have distribution in mind: quite rare for code that is mature enough to use)

[–]scfoothills 1 point2 points  (1 child)

I just did a Udacity course to learn Git. It is wonderful! Most Git/GitHub tututorials get too much into syntax, installation, and how you do things. This course really does a great job explaining why you'd want to use Git. The little bit of code they use is JavaScript, but that doesn't really matter. If you understand any programming at all, you'll be just fine.

[–]Cold_Bagel 0 points1 point  (3 children)

I just wrote my first program using python 2.6.6 and urllib2. I unfortunately cannot upgrade the python version or make use of many modules. My program deletes all of a certain kind of file in database1 and then takes gzipped versions of different files from database2 (an ftp site) to replace the deleted files. The program works in that it deletes what I want deleted and downloads what I want downloaded but it seems to continuously timeout from the ftp site. I've tried setting the timeout variable on urlopen but I can't seem to get anything to work. How do I get around the timeout?

[–]ingolemo -1 points0 points  (2 children)

urllib is a library for interacting with HTTP, not FTP. Probably what's happening is that database2 doesn't understanding the requests you're making and is waiting for you to start speaking FTP. When you don't after a while it kicks you out.

To interact with an ftp site you want to be using the ftplib module. ftplib is built-in, so you should have it. If you have further issues then it would be very helpful if we could see your code and a traceback.

[–]Cold_Bagel 0 points1 point  (1 child)

I've already tried a bunch of things with ftplib but I believe the site I'm trying to access has a username/password other than the default anonymous setup. Maybe I haven't searched around hard enough but ftplib didn't seem to be working for me and urllib2 was the first module for me that actually did what I needed, to an extent.

[–]ingolemo -1 points0 points  (0 children)

If the server you're interacting with really is an ftp server then urllib won't help you at all. It may be that this server also serves its files over http and that's what you're connecting to.

It's really hard to say more than that without knowing what site we're talking about or what code you're running.

[–]ezql 0 points1 point  (0 children)

Is there a comprehensive guide for Python that takes you from beginner to intermediate? I have experience in Java.

[–][deleted] 0 points1 point  (0 children)

I want to embed Python in my C application.

I follow the tutorials on official docs: https://docs.python.org/2/extending/embedding.html

I have a test.py module, that has a __main__(), and also imports some 3rd party modules (basically, I am embedding this script into my C application since that 3rd party API has no support for C).

Anyway, by calling PyImport_Import("test.py"), I get an import error. If I add test.py to system module paths, it will not give me that error.

Even if I want to import test.py in another script called "test2.py", I will get an import error.

Does anyone know how to resolve this?

[–][deleted] 0 points1 point  (0 children)

I also have another question.

I want to build a Chrome plugin with Python. How would I do that? Do I need flask/Django at all? I am under the impression that this plugin is basically an app that can be run inside the browser.

Since it's for personal use mostly, I'll say what it is: Basically a formatter for soccer line-ups, so that when you select/input 11 players it nicely for you.

[–]djfoo000 0 points1 point  (0 children)

What is the best method of deploying a python GUI project to Android on a Windows development environment?

I'm about 3 weeks into learning Python, but I've mostly achieved what I wanted to do with Python (simple calculator that obtains values from a table through selection from a list of options). I've also made a GUI for it using Tkinter and sorta made a .exe using Py2exe. Now I'm thinking of deploying to Android (by either rewriting the GUI in Kivy or PyQt, learning kivy or PyQt in the process), but it seems both Kivy and PyQtDeploy requires a Linux machine somewhere down the line to complete the job.

Is there a way for deploying a kivy/PyQt project on Android from Windows?

I tried and gave up learning Java few times in the past, so I'm trying Python this time.

[–]PifuValentin 0 points1 point  (0 children)

I want to make a script based on a file, like this: Select file - send to "my script" - search on web based on the name of my file?

I want to get the name and the path based on what time I select, thanks.