Solved

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

Posted on 2015-01-19
4
73 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
.properties file to call function/method 9 61
data scientists and AI 17 115
Export Table to CSV - Access to CSV - using python 18 173
windows 10 bash shell 4 48
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…
Introduction On September 29, 2012, the Python 3.3.0 was released; nothing extremely unexpected,  yet another, better version of Python. But, if you work in Microsoft Windows, you should notice that the Python Launcher for Windows was introduced wi…
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
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 …

821 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