Parsing input using the python2.7 argsparse with other Language support - python-2.7

# -*- coding: utf-8 -*-
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("name", help="Enter the name")
args = parser.parse_args()
name = args.name
print name
Command:
python work_space.py அரவிந்த்
Output:
????????
Command
python work_space.py åäö
Output:
σΣ÷
I am not able to get the text which I need, Also I am in need to concatenate this input text, Please let me know what module I have to use and How to implement it?

Related

why cleaning text function doens't work without decoding to UTF8?

I wrote the following function in python 2.7 to clean the text but it doesn't work without decoding the tweet variable to utf8
# -*- coding: utf-8 -*-
import re
def clean_tweet(tweet):
tweet = re.sub(u"[^\u0622-\u064A]", ' ', tweet, flags=re.U)
return tweet
if __name__ == "__main__":
s="sadfas سيبس sdfgsdfg/dfgdfg ffeee منت منشس يت??بمنشس//تبي منشكسميكمنشسكيمنك ٌاإلا رًاٌااًٌَُ"
print "not working "+clean_tweet(s)
print "working "+clean_tweet(s.decode("utf-8"))
Could any one explain why?
Because I don't want to use the decoding as it makes the manipulation of the text in Sframe in graphlab is too slow.

extracting javascript code from html

i would want to extract the id of this statement , how could i proceed with this in python.
i am a beginner in python.
javascript:return WebForm_FireDefaultButton(event, 'ctl00_ibtnFind')
#!/usr/bin/python2
# -*- coding: utf-8 -*-
import re
input = """
javascript:return WebForm_FireDefaultButton(event, 'ctl00_ibtnFind')
javascript:return WebForm_FireDefaultButton(event, 'ctl00_ibtnFind2')
"""
m = re.findall("javascript:return WebForm_FireDefaultButton\(event, '([^']+)'\)", input)
print m

How to receive the arguments in python sub process runnable file

subprocess.Popen(['python', downloadscript.py, "--longitude", long, "--latitude", lat, "--download_to", ],stdout=subprocess.PIPE)
I want to get the longitude, latitude and download_to in downloadscript.py file
The most pythonic way to parse arguments in Python is the module argparse:
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("longitude", help="enter longitude")
parser.add_argument("latitude", help="enter latitude")
parser.add_argument("download_to", help="target directory")
args = parser.parse_args()
latitude = args.latitude
Read more about it here: https://docs.python.org/2/howto/argparse.html
cmd='python downloadscript.py --longitude "{lo}" --latitude "{la}" --download_to "{d}"'\
.format(lo=long,la=latitude,d=down_to)
subprocess.Popen(cmd,stdout=subprocess.PIPE,shell=True)
Assuming you set a convention of -arg_name arg_value,
You can use this snippet in your downloadscript.py file:
import sys
k=''
args={}
for a in sys.argv:
if a.startswith('-'):
k=a.replace('-','')
continue
args[k]=a
print (args)# {longitude:'value',latitude:'value',download_to:'value'}
If you are using python 2.7 or above, you can use the argparse module.
(Note that the default python version for many common linux distributions is 2.6.x)

Can't output in Russian_Python2.7.9

I can't make output in Russian language only output of Unicode=(
I use Pythonv.2.7.9
Microsoft 8
How I can do that with list?
#! /usr/bin/env python
# -*- coding: utf-8 -*-
import requests
from bs4 import BeautifulSoup
r = requests.get("http://fs.to/video/films/group/film_genre/")
response = r.content.decode('utf-8')
page = BeautifulSoup(response)
for tag in page.findAll('li'):
a = tag.find('a')
for b in a.contents:
print (u'{0}'.format(u'○'),unicode(b.string))
Example of output must be like:
Аниме
Биография
...
Фэнтези
Эротика
Change the last line to:
print (u'{0}'.format(u'○'),b.string

Error while executing python code

# -*- coding: utf-8 -*-
# coding: utf-8
import sys
import os
import time
b = 'sudo tshark -i eth0 -R “tcp contains “attack”” -T fields -e ip.src -a duration:60>output.txt'
a = os.popen(b)
time.sleep(32)
f = open('output.txt','r')
text = 'IP address of attacker is'
print (text), f.read()
f.close
I am trying to execute this code to capture packets using tshark but i am getting this error:
tshark: "�" was unexpected in this context.
Please help me why that error is caused, thank you
The error message is because tshark tries to disable some dangerous functions in Lua like dofile.
If you don't need Lua in tshark, you can disable Lua support: edit init.lua, change disable_lua = false to disable_lua = true.
If you need Lua support, read Platform-Specific information about capture privileges, see how to capture packets without root rivilege.