Solved

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

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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Variable is a place holder or reserved memory locations to store any value. Which means whenever we create a variable, indirectly we are reserving some space in the memory. The interpreter assigns or allocates some space in the memory based on the d…
Sequence is something that used to store data in it in very simple words. Let us just create a list first. To create a list first of all we need to give a name to our list which I have taken as “COURSE” followed by equals sign and finally enclosed …
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
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…

757 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now