Solved

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

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Python: sort dictionary of dictionaries 4 107
Is my Java RTS game window portable to Python? 7 97
Trying to run a Python File 11 63
Python:Remove duplicates without sorting? 5 75
Plenty of writing has gone on the web trying to compare Python with other competitive programming languages and vice versa. However, not much has been put into a wholistic perspective. This article should help you decide whether to adopt Python as a…
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…
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 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…

861 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

23 Experts available now in Live!

Get 1:1 Help Now