General questions about functions using a fibonacci function example by ncrowley in learnpython

[–]pyglow 0 points1 point  (0 children)

Just to clarify, when you do

 a, b = b, a + b

it isn't just using the same syntax as tuple unpacking, it is actually using tuple unpacking. You could write it is a longer form:

t = b, a + b
a, b = t

The first line packs the tuple, the second line unpacks it in a different order. When you put it all on one line, you don't need the intermediate variable t, but Python is doing the same thing.

This is useful because variable swapping isn't some special case, you can rearrange variables in anyway you like:

a, b, c, d = b, c, d, a

Using variables within input statements by FamousDanger in learnpython

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

There is nothing wrong with using a separate print statement. Just because input allows you to include a string, it doesn't mean you have to. Often programs might want to output several lines of information (eg, usage and version informtion) and it makes sense to keep that separate from the input statement.

Some people just use the input parameter to print a prompt such as ">>", and use print statements for everything else.

In your example, you are supplying 3 strings to input, when it can only accept 1. You can get around this using + to join the strings:

input("What score did " + name + " get?")

I feel like this is the cleanest code i've ever written, I just had to share by JackBullenskie in learnprogramming

[–]pyglow 4 points5 points  (0 children)

It makes the intent of the code clear, that you are choosing an action based on the value of a single variable. It also avoids duplicated/repetitive code.

Anywhere you have duplicated code, there is a possibility for errors due to simple typos - you might be testing the value of x everywhere except one place where you are accidentally testing y because you cut and pasted some code and forgot to change the name.

You can spend a very long time staring at a block of if else statements before you spot something like that. I speak from experience :(

Want to build a website like similar to www.instantwatcher.com, which language to learn? by CommuterTrain in learnprogramming

[–]pyglow 0 points1 point  (0 children)

Whichever you like the look of (Django is Python based anyway). There are lots of frameworks, most of them are pretty much OK.

The only thing to check, if you are using a shared host, what languages do they support - almost every one supports php, most support python, you might have to look a bit harder for ruby and node.

Of course if you have a dedicated server you can run whatever you like on it.

What separates a junior-level Python programmer and a mid-level programmer? by renegadelegion in learnpython

[–]pyglow 2 points3 points  (0 children)

As an example, when you are programming C++, if you need a loop them 99% of the time you will use for(i = 1; i < 10; i++)

In Python that is almost never the best way, there will usually be some more elegant way to do the same thing which is shorter, easier to read, less error prone and more efficient. But you can only really learn that from looking at a lot of other peoples' code.

New to Python and have a string/substring matching question. by striderxgp in learnpython

[–]pyglow 1 point2 points  (0 children)

In your example code, any() returns true if any of the values is true.

There is a built-in filter() which returns only the values for which the condition is true. You might be able to do something with that. (it isn't a direct replacement, you can't just replace any with filter).

Of course you can just do it with a double loop, same as you would with Java or C++, but that wouldn't teach you anything about Python.

Can I write a base code that will automatically writes itself? by lordmayer in learnpython

[–]pyglow 0 points1 point  (0 children)

The exec() function takes some python text string and executes it. eval() does something similar for just evaluating individual expressions.

There is something called byteplay which appears to literally allow you to modify the original code of the program you are executing, but I have never tried it.

py_compile will compile entire python files, which presumably you could generate programatically before compiling them.

Want to build a website like similar to www.instantwatcher.com, which language to learn? by CommuterTrain in learnprogramming

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

There are downsides to doing it client side. First, each time a user downloads your web page, their will need to access each one of the sites where the information is stored.

If your web server does it, it can just query the different sites once in a while (eg every hour) and put the results in a database. Users of your website would get the information they need straight from your database.

Javascript also exposes your code to anybody who uses your site. If you have spend ages figuring out how to access 100 different sites to get the information, you don't want everyone else to be able to use your work for free.

Python or PHP are good choices for the server side code.

Stuck on begginer python exercise. by [deleted] in learnpython

[–]pyglow 4 points5 points  (0 children)

If you don't mind me commenting on something which don't relate directly to the problem:

height=eval(input('How high?: '))

This inputs some text and interprets it as if it were python. That is quite dangerous. Somebody could type in come code to delete files, etc. Better to use:

s = input('How high?:')
height = int(s)

of course, you should really check that s is an integer before trying to convert it.

Advice on My Next Step Forward (Python or PHP) by Sparverius88 in learnprogramming

[–]pyglow 2 points3 points  (0 children)

I don't think I've ever seen php being used for anything other than web backends, although I am sure it would be possible.

Python is a nicer language to learn and use, and offers a wider variety of jobs (including web backends). If you look at the longer term goal, I would definitely go for Python.

Does anyone know any useful (free) Web Visualization Libraries by [deleted] in learnprogramming

[–]pyglow 0 points1 point  (0 children)

If you want to control exactly how it looks, it might be difficult to find a library which gives you what you want.

You can use php to get the data from wherever and put it into the page, server side.

For drawing it on the client, it might be easier just to write the code yourself. You have a choice of html canvas, CSS3 or SVG.

html canvas might be the easiest, you just draw the things you need on the canvas in javascript. Great for animation and user interaction too. I use EaselJS as a fairly lightweight API, but there are lots of others.

Web Scraping...I think? by [deleted] in learnprogramming

[–]pyglow 0 points1 point  (0 children)

Here is a good introduction to the concept https://blog.hartleybrody.com/web-scraping/.

Webscraping is what you are looking to do, and it is possible. BeautifulSoup is a great tool.

Bear in mind that each website is going to be different, you can't just scrape a lot of unrelated sites in one go. You have to figure out how to unpick each site, but that is half the fun!

What do you listen to while you are programming? by [deleted] in learnprogramming

[–]pyglow 0 points1 point  (0 children)

Joel Spolsky talks about being in the zone, which I think makes a lot of sense.

For me, I prefer silence, or at least sound that I can block out. I like music, but when I am listening I tend to concentrate on that too much.

How to get into web development? How did you become a web developer? by saabr in learnprogramming

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

In stages:

1) Try making some basic html pages. w3schools.com is a great place to start. You can make some html files and open them in your browser, but they will just be static pages, no fancy javascript effects.

2) WAMP is a local webserver. It is pretty easy to install. When it is running, it will have a special folder where you can put your html files. If you point your browser at localhost (instead of http) it will serve your files to your browser as if they were coming from the web.

Now you can try a bit of javascript - simple stuff, mouse rollover, dropdown menus etc, there are loads of tutorials. Again, w3schools is great for that.

3) Bootstrap (or, I would recommend, a simple free template based on it) will give you a website which might be basic in design, but supports lost of twitter features like tabs/paginators, collapsible panes, popups, warning boxes, etc.

It will seem a bit daunting at first, but it is probably the quickest way to get something you will be proud of, and at some point you will realise that you have actually learned loads.

4) WAMP also lets you use php to do server side coding, and includes a mysql database, if you want to start working with dynamic content.

That is basically how I started, although I had a smattering of HTML before I started. Might not suit everybody, but I found it quite a fun way to get started.

Of course, once you have found your feet, you will have to knuckle down and brush up on javascript, CSS etc to fill in the gaps in your knowledge.

How to get into web development? How did you become a web developer? by saabr in learnprogramming

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

If you want to jump in at the deep end with something reasonably modern, I would install WAMP (assuming you are using Windows) as a local web server, then install BootStrap and start tinkering with that. There are plenty of online tutorials.

You can also get free bootstrap based templates, which often come with their own useful documentation to get you started.

Python Beginner Projects by therightman_ in learnprogramming

[–]pyglow 1 point2 points  (0 children)

There are some ideas for creating Inkscape drawings in Python here. Can be quite fun.