Solved

how to créate a fonction python for importation on order files  python

Posted on 2015-01-19
4
72 Views
Last Modified: 2015-01-24
hello

my code for fonction

http://pastebin.com/5YpgRG0N

i would like create a fonction and get the variable name with my principal script

the script required a argument :)

ty all
0
Comment
Question by:Gaaara
  • 3
4 Comments
 
LVL 16

Assisted Solution

by:gelonida
gelonida earned 50 total points
ID: 40558247
Could you explain the problem a little better?

I think you will get better and more interesting answers if you help us a little.

It seems you pass a url as argument, fetch some html code from it and try to parse it for some information, that you're interested in.

What variable name are you talking about?
0
 

Author Comment

by:Gaaara
ID: 40558261
this script get the title tag and modify this and généraite a variable
http://pastebin.com/5YpgRG0N
print(oname_cleanedup)

Open in new window

and i would like use the script separately on the principal python script

and use the variable
print(oname_cleanedup)

Open in new window



on the principal script

this script need argument

python my.py http://www.blabla.com 

Open in new window

0
 

Accepted Solution

by:
Gaaara earned 0 total points
ID: 40558451
i solved my question

secondary script
# -*- coding: UTF-8 -*-
import subprocess
from bs4 import BeautifulSoup
import  requests
import  re
import sys

def function(olinks):
    headers = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537)'}
    session = requests.Session()
    response = session.get(olinks, headers=headers)
    soup = BeautifulSoup(response.content)
    oname = soup.find("title")
    if oname.text.find('Saison') >= 0:
        regexp = r'(.*?\s+-\s+S)aison\s+(\d+)\s+\xc9.*?(\d+)(.*)'
        subst = "{title} {season:02d} Ep {episode}"
    else:
        regexp = r'(.*?\s+-)(\s+)\xc9.*?(\d+)(.*)'
        subst = "{title} Ep {episode}"
    return re.sub(regexp,lamb

Open in new window


principal script

from test2 import function
import sys

givenURL = sys.argv[1]
oname_cleanedup = function(givenURL)

print (oname_cleanedup)

Open in new window

0
 

Author Closing Comment

by:Gaaara
ID: 40567967
is resolved
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Less strange, but still introduction This introduction was added (1st August, 2011) to reflect some reactions.  Firstly, the term basics in the title of the article...  As any other word, it is a symbol with meaning attached to the word by some a…
Installing Python 2.7.3 version on Windows operating system For installing Python first we need to download Python's latest version from URL" www.python.org " You can also get information on Python scripting language from the above mentioned we…
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…

786 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question