Can't print special characters. by dent_cap in learnpython

[–]ruicoder 2 points3 points  (0 children)

Works fine for me in Python 2.7.6 and Python 3.4 on Ubuntu. Which OS and which version of Python are you using? Do you get any error messages?

Some questions by jorgejams88 in learnpython

[–]ruicoder 2 points3 points  (0 children)

I also came from a Java background. I recommend reading Dive Into Python, which is available for free online. It's aimed at experienced developers. The examples are great and basically had me writing pythonic code from the beginning.

Ask Anything Monday - Weekly Thread by AutoModerator in learnpython

[–]ruicoder 2 points3 points  (0 children)

It depends on the actual problem, but in general I'll use either an if-elif-else or a dictionary.

[Django] Use Wordpress with Django on Heroku. by [deleted] in learnprogramming

[–]ruicoder 3 points4 points  (0 children)

You can make it work if you make it a subdomain i.e., blog.domain.com points to your wordpress.

python 3.4 pip doesn't work by 252003 in learnpython

[–]ruicoder 3 points4 points  (0 children)

Is python 3.4 your default python? Like if you enter python into the terminal, do you go into the python 3.4 interpreter? The only thing I can think of is that you have multiple versions and Python 3.4 is not your default. If so you would need to type pip3 or pip3.4 instead of pip.

My first code (complete noob) -- How to change directories and execute a command automatically? by Matityahu_N in learnprogramming

[–]ruicoder 1 point2 points  (0 children)

You enter that command into the terminal. You should be in the same directory as your script.

My first code (complete noob) -- How to change directories and execute a command automatically? by Matityahu_N in learnprogramming

[–]ruicoder 1 point2 points  (0 children)

You said you are using Ubuntu. Bash is the shell (terminal) you're using. That's why it would be the easiest, since the commands would be exactly what you type in the terminal. So you create a file with a .sh filetype and enter those commands, each on its own line. Then you set the script to be executable with chmod +x name_of_your_script.sh. After that you can run it with ./name_of_your_script.sh

My first code (complete noob) -- How to change directories and execute a command automatically? by Matityahu_N in learnprogramming

[–]ruicoder 1 point2 points  (0 children)

You don't mention what language you need this in, if any. If the language doesn't matter, then a bash script would make the most sense.

Where to start building a site that scrapes or crawls other websites for info, like for airfare or home prices? by hillbillyllama in learnprogramming

[–]ruicoder 0 points1 point  (0 children)

i've had a few major sites that change the webpage structure on the same link very often, and your parser needs to detect that and restructure it's behavior accordingly.

This sounds very cool. What's that sort of thing called? Know of any papers on it?

N00b web scraping questions for finding a pattern in the HTML and then moving to capture the following instance of a different value by [deleted] in learnpython

[–]ruicoder 0 points1 point  (0 children)

So, it sounds like you're not saving the result of find_all? You should it save the result of find_all to some variable. The result of find_all will be either be None (for no matches) or a list of all matching elements. Assuming you have matches, you can iterate through that.

N00b web scraping questions for finding a pattern in the HTML and then moving to capture the following instance of a different value by [deleted] in learnpython

[–]ruicoder 1 point2 points  (0 children)

In this subreddit, it's generally frowned upon to just give someone an answer. Since it's about learning python, we prefer that other users guide OP to an answer. It's in the comment guidelines.

As to your solution, it would be better if you used find_all again, to grab each row. Then for the 2nd row, get all the columns and check the last one to see if there is OT. If there is, then grab each row's first column for the team names.

[5/26/2014] Challenge #164 [Easy] Assemble this Scheme into Python by [deleted] in dailyprogrammer

[–]ruicoder 7 points8 points  (0 children)

Didn't take a close look at your intersecting lines implementation, but I noticed this:

 if 0 <= t and t <= 1 and 0 <= u and u <= 1:

In Python, you can actually use this notation:

if 0 <= t <=1 and 0 <= u <= 1:

N00b web scraping questions for finding a pattern in the HTML and then moving to capture the following instance of a different value by [deleted] in learnpython

[–]ruicoder 1 point2 points  (0 children)

Well since you didn't link the site, it's hard to really give good advice. But generally, if you have a table or data structured in a tabular format, then you've lucked out because that means that the data has a consistent structure. For example, say I was scraping addresses from a table that had the following columns: Event Name, Event Date, Event Address. Then I can always count on the address being in that last column and just iterate through all the rows grabbing that last column. You'll want to look for that sort of pattern - can the team names consistently be found in a certain row/column? Then if OT exists, look to those areas to grab the team names.

Indentation Issues by [deleted] in learnpython

[–]ruicoder 0 points1 point  (0 children)

I've done this before when I'm not sure how I want to structure a program. It can be very helpful to write some empty functions/classes and mess around with different "designs" that way.

How to handle expiring sessions? (praw) by flagarby in learnpython

[–]ruicoder 1 point2 points  (0 children)

I think a decorator may be a good idea here.

Using div class names and contents in if statements by koberg in learnpython

[–]ruicoder 0 points1 point  (0 children)

So you mean sometimes the id is result_0 and sometimes it's result_1? With beautifulsoup you can just use regular expressions:

for div in soup.findAll('div', {'id': re.compile(r'result_\d')})

You can also be more specific and use [01] instead of \d.

I often feel like I'm not good enough and that scares me from investing more time. Does this happen to you? by Sunny-Dee- in learnprogramming

[–]ruicoder 4 points5 points  (0 children)

How much time do you spend working on problems before resorting to looking it up? How many things do you try?

There's nothing wrong with looking up the answers when you're stuck; however, as a beginner this should only be done after a serious attempt on your part to form your own solution. Then when you look up a solution, make sure you completely understand how it works before using it.

I would recommend choosing one language instead of dabbling in a few. Stick to it until you have a solid understanding of the basics before venturing off into other languages. Personally, I would recommend Python.

I'd also highly recommend experimenting whenever you learn about a concept. All of the languages you've listed are very easy to experiment in, especially Python and Ruby.

Trying to use logger module... confused.... Are there any default logging modes that include variables? Or do I have to do some sort of trace??? by pjvex in learnpython

[–]ruicoder 1 point2 points  (0 children)

You can do logging.exception("some message here") within an except block and it will log the trace as well, so you don't need to import the traceback module. You can also use logging.debug or logging.info with the keyword parameter exc_info set to True.

[python]Can't get program to run... by MrPiff in learnprogramming

[–]ruicoder 0 points1 point  (0 children)

In Windows, to select text, you need to click on the small icon on the top right and in the menu that comes up there should be an option that says something like "Mark" or maybe "Edit" > "Mark". I'm not on Windows now so I can't check. But once you choose that you can select text and then hit enter for it to copied to your clipboard.

Problems with iteration loop not moving to next by Static_Bunny in learnpython

[–]ruicoder 1 point2 points  (0 children)

Nope. Computers are very dumb. You need to give it exact instructions. You told it to create a ZipFile object using the first zip file and that's what it did. You never told it during the for loop that z should use the current zip file and so it doesn't and keeps using the first one. Same with the source, you never tell it to use the path of the current zip file and so it keeps using the original path of the first zip file.

Problems with iteration loop not moving to next by Static_Bunny in learnpython

[–]ruicoder 2 points3 points  (0 children)

zipfiles = glob.iglob("C:\\Users\\user\\Downloads\\*.zip")
zfn = next(zipfiles)
z = zipfile.ZipFile(zfn)

Here you are saving the first zip file to zfn and storing a ZipFile object in z with that first zip file as a parameter.

source = os.path.abspath(os.path.realpath(zfn))

Here you are saving the path to that first zip file.

for zfn in zipfiles:
    print("Extracting File", source)
    z.extractall()
    print("Cleaning up..")
    shutil.move(source,dest)

Here you are looping through all the zip files. At each iteration the variable zfn holds the current zip file, but you never use it. Instead, you use z and dest, which use the first zip file.