Re: [Tutor] debug and execute python code in Mac
On Wed, Aug 27, 2014 at 7:14 AM, Najam Qasim wrote: > What is preferable method to debug and execute python code in Mac? > > I do not like the cmd/terminal execution. Thanks ! > > > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > https://mail.python.org/mailman/listinfo/tutor > I don't know many ways to debug code that don't involve the terminal in some fashion. Even with a good IDE you're going to have a terminal built in for output. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python advice about API, JSON
On Mon, Sep 22, 2014 at 4:01 PM, Juan Christian wrote: > I'm trying to make my script the more pythonic possible. How would a good > approach regarding external API and json be? I don't think dealing with a specific API is actually appropriate for this list. I'll try to answer the general elements. > I'm calling this API (http://docs.themoviedb.apiary.io/) using 'requests'. > The thing is that I need to do a bunch of different calls to the API: > > - http://api.themoviedb.org/3/person << Receive ID and return person info > - http://api.themoviedb.org/3/tv << Receive ID and return serie info > - http://api.themoviedb.org/3/movie << Receive ID and return movie info > - http://api.themoviedb.org/3/search << Receive "Name of person or serie or > movie" and return ID > > I have the following structures: > > - {query}/{type}?api_key={key}&query={person or tv or movie} > - {query}/{id}?api_key={key} > - {query}/{id}/credits?api_key={key} > - {query}/{id}/season/{season_numer}?api_key={key} > - {query}/{id}/season/{season_numer}/episode/{episode_number}?api_key={key} > - > {query}/{id}/season/{season_numer}/episode/{episode_number}/credits?api_key={key} > > > I'm thinking about creating a class 'API' and have all these URLs and > structures there. The thing is that I need to pass my API_KEY and this key > will be used for everything, so I just need to pass it once, how can I do > that? Yes, I know about class attributes, but the thing is that I will call > this class 'API' from different classes and I'll need to instantiate a API > obj in each of them, is it a good approach? Inside this 'API' class I would > have a __init__ that would receive an API_KEY and different methods, each > for a type of query (person, tv, movie, search, credits). First question: Why do you need multiple versions of this theoretical class floating around? Perhaps if you wrote a single module api that handles interactions with the API, you can then import that module into any other module that will use the API, and you only have to write all of this once. > Maybe my explanation is a bit confusing but I hope you guys understood, > anyway, you can ask for more information if needed! > > And another thing, What's better, a single module with multiple classes > (total lines: ~110) or multiple modules with 1-3 classes (correlated, like > class serie, season and episode in the same module, and class person and > character in the same module) each? I personally prefer multiple modules, though it absolutely depends on the demands of the project. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Class errors
If the code I'm seeing is correct, the problem is the class is Jobs, and you instantiated a Job, which doesn't exit. Replace one with the other in either case should fix it. On Thu, Jan 22, 2015 at 11:11 AM, jarod...@libero.it wrote: > Dear All, > > I created a class that invoke from another file another class > I get an error that I do not understand: gobal name Job is not defined > However If I see the class imported I found the class Job. > Any suggestion or example on class invoke another class > > #job,py > class Jobs: > . > > #trial.py > > from core.job import * > class Second: > def __initi__: > tp = open("/tmp/file.txt") > > def gus(self): > tr = Job() > > thanks so much!1 > > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > https://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python for linux
You're actually asking multiple subquestions here, let me start by asking a clarifying question: When you say "log in to the Linux machine" I assume you mean you need to access a remote host? Your script will be running locally? Next your other questions: Checking permissions of a file: Look into the os module. Checking for substrings: This is has many answers. Have you tried to do this yet? Patrick On Tue, Jan 27, 2015 at 11:50 AM, Reuben wrote: > Hello, > > I wish to know which python module works well with Linux commands - for > e.g. Searching a string in file, number of occurrences of a string in a > file, what is the permission of a file. > > To test this operation I need my python script to login into the Linux > machine and then perform the above mentioned operations > > Any specific pointers to help me with this task? > > Thanks > > Regards, > Reuben > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > https://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] List comprehensions to search a list--amazing!
>>> The generalized problem: >>> >>> L = [V0, V1, ..., Vn], where V0 >= V1 >= V2 >= ... >= Vn . >>> Find index i, such that V[i] >= Vt >= V[i + 1], where Vt is the test >>> value being searched for. I need to know the indices i and i + 1, >>> which I need to interpolate based on where Vt falls. >>> >>> The solution (As a sublist, S) I worked out tonight after >>> experimenting with comprehension syntax is: >>> S = [i for i, V in enumerate(L) if L[i] >= Vt >= L[i + 1]] >>> >>> And, of course, the index i I need is: >>> i = S[0] >>> >>> I tested this out with concrete examples in the interpreter, such as >>> with a list, L: >>> >>> L = [item for item in range(1, 0, -1)] >>> >>> and trying different test values. It was blazingly fast, too! >>> >>> All I can say is: WOW!!! > > By the way, if you were to use a plain old loop the expected speedup over > the listcomp would be 2. You can break out of the loop when you have found > the gap, after iterating over one half of the list on average. > > So for-loops are twice as amazing ;) For the same basic speed up, a generator expression with a call to next() will produce similar results. Without the additional code to get the indexed item. index = (i for i, _ in enumerate(original_list) if original_list[i] >= target >= original_list[i + 1]).next() The only catch is it raises a StopIteration exception if no element fits the test. P ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor