-2

I have a simple question: I have this code:

# open an HTML file on my own (Windows) computer url = "$user data here" webbrowser.open(url,new=new) 

I need to have it so that when it is run the user can enter lets say 3 different URL's and have that code created two more times filling in the variable spot with one of the three variables in each part.

I would assume I need a loop but how can I define the variables dynamicly that way if they enter 3 or 5 urls it would generate the code to do that?

Thanks in advance, Justin

1
  • 6
    I think you'd better start with some basic Python tutorial. Commented Nov 2, 2012 at 18:29

4 Answers 4

1

do you mean you want to grab urls like:

urls = raw_input("Enter yer urls! ") 

?

if so, you could just split the result and open windows for each url with something like:

for url in urls.split(): webbrowser.open(url,new=new) 
Sign up to request clarification or add additional context in comments.

1 Comment

This is exactly what I needed now what about if I need a variable to go between the url ie www.website.com/story/<user input article number>? I have done this before and remember needing some code around the variable the cleaned it up something like . var . or something like that.
1

Create an empty list. Use the list.append method to keep adding to this list whenever you need too, thereby achieving the effect you need without actually using dynamic variables.

Comments

1

If the user enters the urls, separated by a space, like this:

urls = "http://stackoverflow.com http://google.com" 

then you can call webbrowser.open in a loop once for each url like this:

for url in urls.split(): webbrowser.open(url,new=new) 

Comments

0

Create a list with no values and use the append method in the list to dynamically assign the values to the list which you can use for iterate.

Use comma to seperate between various urls

input = raw_input("Enter urls separted by commas ") urls=input.split(",") 

For iterate over varibles use "For" loop

for value in urls: webbrowser.open(value,new=new) 

I hope this solves ur issue of having dynamically giving input for a function

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.