Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2015-01-19
4
Medium Priority
?
78 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 17

Assisted Solution

by:gelonida
gelonida earned 200 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Flask is a microframework for Python based on Werkzeug and Jinja 2. This requires you to have a good understanding of Python 2.7. Lets install Flask! To install Flask you can use a python repository for libraries tool called pip. Download this f…
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 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 while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…
Suggested Courses

719 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