python import module question

2013-07-27 Thread syed khalid
I am trying to do a "import shogun" in my python script. I can invoke shogun 
with a command line with no problem. But I cannot with a python import 
statement.

>invoking python from a command line...

Syedk@syedk-ThinkPad-T410:~/shogun-2.0.0/src/interfaces/cmdline_static$ shogun 
| more
libshogun (i686/v2.0.0_9c8012f_2012-09-04_09:08_164102447)

Copyright (C) 1999-2009 Fraunhofer Institute FIRST
Copyright (C) 1999-2011 Max Planck Society
Copyright (C) 2009-2011 Berlin Institute of Technology
Copyright (C) 2012 Soeren Sonnenburg, Sergey Lisitsyn, Heiko Strathmann
Written   (W) 1999-2012 Soeren Sonnenburg, Gunnar Raetsch et al.

( configure options: "configure options --interfaces=python_static" compile flag
s: "-fPIC -g -Wall -Wno-unused-parameter -Wformat -Wformat-security -Wparenthese
s -Wshadow -Wno-deprecated -O9 -fexpensive-optimizations -frerun-cse-after-loop
-fcse-follow-jumps -finline-functions -fschedule-insns2 -fthread-jumps -fforce-a
ddr -fstrength-reduce -funroll-loops -march=native -mtune=native -pthread" link
flags: " -Xlinker --no-undefined" )
( seeding random number generator with 3656470784 (seed size 256))
determined range for x in log(1+exp(-x)) is:37 )

>>>Trying to call python from a script in the same directory where I invoked 
>>>the shogun from a command 
>>>linesyedk@syedk-ThinkPad-T410:~/shogun-2.0.0/src/interfaces/cmdline_static$ 
>>>python
Python 2.7.3 (default, Apr 10 2013, 05:46:21)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import shogun
Traceback (most recent call last):
  File "", line 1, in 
ImportError: No module named shogun
>>>



Regards
-- 
http://mail.python.org/mailman/listinfo/python-list


importing modules

2013-07-31 Thread syed khalid
I am attempting to import modules from Shogun to python from a non-standard
python directory ie from my /home/xxx directory. is there a way on ubuntu
to selectively some modules, scripts, data  from one directory and others
modules, scripts from another directory. In other words, is there a file(s)
that provide pointers to where these modules are located.

regards

Sy
--
-- 
http://mail.python.org/mailman/listinfo/python-list


Python script that does batch find and replace in txt files

2014-11-09 Thread Syed Khalid
Python script that does batch find and replace in txt files Need a python 
script that opens all .txt files in a folder find replace/delete text and save 
files.

I have text files and I need to perform below steps for each file. 

Step 1: Put cursor at start of file and Search for "Contact's Name:". Delete 
all the rows before it.
Step 2: Put cursor at end of file, Search for "Contact's Name:" select option 
UP.
Step 3: Search for "Photo of the" Replace with blanks
Step 4: Search for "Contact is" Replace with blanks
Step 5: Search for "Contact's Name:" Replace with blanks
Step 6: Search for "Age:" Replace with blanks
Step 7: Search for "Sex:" Replace with blanks
Step 8: Search for "House No:" Replace with blanks
Step 9: Search for "available" Replace with blanks
Step 10: Remove Empty Lines Containing Blank Characters from file
Step 11: Trim Leading Space for each line
Step 12: Trim Trailing Space after each line
Step 13: Search for - (hyphen) Replace with _ (underscore)
Step 14: Save file.

Currently I have recorded a macro in Notepad++.
I open each file, run macro and save file.
As there are many files I was looking for a program to automate the process. 

I posted the same query in Notepad++ forum. I got a reply that it can be done 
by using Python script.

Kindly do the needful. 

Thank you.
khalidness

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python script that does batch find and replace in txt files

2014-11-09 Thread Syed Khalid
Hi Albert,

Thank you for script.

I am getting the below error :

  File "EamClean.log", line 12
with codecs.open(txt + "_out.txt", "wb", encoding="utf-8") as w:
   ^
SyntaxError: invalid syntax

Kindly do the needful.

On Mon, Nov 10, 2014 at 1:53 AM, Albert-Jan Roskam  wrote:

>
>
>
>
> - Original Message -
> > From: Syed Khalid 
> > To: python-list@python.org
> > Cc:
> > Sent: Sunday, November 9, 2014 8:58 PM
> > Subject: Python script that does batch find and replace in txt files
> >
> > Python script that does batch find and replace in txt files Need a
> python script
> > that opens all .txt files in a folder find replace/delete text and save
> files.
> >
> > I have text files and I need to perform below steps for each file.
> >
> > Step 1: Put cursor at start of file and Search for "Contact's
> > Name:". Delete all the rows before it.
> > Step 2: Put cursor at end of file, Search for "Contact's Name:"
> > select option UP.
> > Step 3: Search for "Photo of the" Replace with blanks
> > Step 4: Search for "Contact is" Replace with blanks
> > Step 5: Search for "Contact's Name:" Replace with blanks
> > Step 6: Search for "Age:" Replace with blanks
> > Step 7: Search for "Sex:" Replace with blanks
> > Step 8: Search for "House No:" Replace with blanks
> > Step 9: Search for "available" Replace with blanks
> > Step 10: Remove Empty Lines Containing Blank Characters from file
> > Step 11: Trim Leading Space for each line
> > Step 12: Trim Trailing Space after each line
> > Step 13: Search for - (hyphen) Replace with _ (underscore)
>
> > Step 14: Save file.
>
> something like (untested)
>
>
> import glob, codecs, re, os
>
> regex = re.compile(r"Age: |Sex: |House No: ") # etc etc
>
> for txt in glob.glob("/some/path/*.txt"):
> with codecs.open(txt, encoding="utf-8") as f:
> oldlines = f.readlines()
> for i, line in enumerate(oldlines):
> if "Contact's Name: " in line:
> break
> newlines = [regex.sub("", line).strip().replace("-", "_") for line in
> oldlines[i:]
> with codecs.open(txt + "_out.txt", "wb", encoding="utf-8") as w:
> w.write(os.linesep.join(newlines))
>
>
>
>
> >
> > Currently I have recorded a macro in Notepad++.
> > I open each file, run macro and save file.
> > As there are many files I was looking for a program to automate the
> process.
> >
> > I posted the same query in Notepad++ forum. I got a reply that it can be
> done by
> > using Python script.
> >
> > Kindly do the needful.
> >
> > Thank you.
> > khalidness
> >
> > --
> > https://mail.python.org/mailman/listinfo/python-list
> >
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python script that does batch find and replace in txt files

2014-11-09 Thread Syed Khalid
My Script, 

I have added 

import glob, codecs, re, os

regex = re.compile(r"Age: |Sex: |House No: ") # etc etc
Script I executed in EditRocket :

for txt in glob.glob("/D:/Python/source/*.txt"):   
with codecs.open(txt, encoding="utf-8") as f:
oldlines = f.readlines()
for i, line in enumerate(oldlines):
if "Contact's Name:" in line:
break
newlines = [regex.sub("", line).strip().replace("-", "_") for line in 
oldlines[i:]
with codecs.open(txt + "_out.txt", "wb", encoding="utf-8") as w:
w.write(os.linesep.join(newlines))


Error Message :

  File "EamClean.log", line 12
with codecs.open(txt + "_out.txt", "wb", encoding="utf-8") as w:
   ^
SyntaxError: invalid syntax

Kindly do the needful



-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python script that does batch find and replace in txt files

2014-11-09 Thread Syed Khalid
Code after adding path of .txt files :

import glob, codecs, re, os

regex = re.compile(r"Age: |Sex: |House No: ") # etc etc

for txt in glob.glob("D:/Python/source/*.txt"):
with codecs.open(txt, encoding="utf-8") as f:
oldlines = f.readlines()
for i, line in enumerate(oldlines):
if "Elector's Name:" in line:
break
newlines = [regex.sub("", line).strip().replace("-", "_") for line in
oldlines[i:]
with codecs.open(txt + "_out.txt", "wb", encoding="utf-8") as w:
w.write(os.linesep.join(newlines))


I executed code in edit rocket.

Error message :


File "EamClean.log", line 12
with codecs.open(txt + "_out.txt", "wb", encoding="utf-8") as w:
   ^
SyntaxError: invalid syntax





On Mon, Nov 10, 2014 at 2:22 AM, Syed Khalid  wrote:

> Hi Albert,
>
> Thank you for script.
>
> I am getting the below error :
>
>   File "EamClean.log", line 12
> with codecs.open(txt + "_out.txt", "wb", encoding="utf-8") as w:
>^
> SyntaxError: invalid syntax
>
> Kindly do the needful.
>
> On Mon, Nov 10, 2014 at 1:53 AM, Albert-Jan Roskam 
> wrote:
>
>>
>>
>>
>>
>> - Original Message -
>> > From: Syed Khalid 
>> > To: python-list@python.org
>> > Cc:
>> > Sent: Sunday, November 9, 2014 8:58 PM
>> > Subject: Python script that does batch find and replace in txt files
>> >
>> > Python script that does batch find and replace in txt files Need a
>> python script
>> > that opens all .txt files in a folder find replace/delete text and save
>> files.
>> >
>> > I have text files and I need to perform below steps for each file.
>> >
>> > Step 1: Put cursor at start of file and Search for "Contact's
>> > Name:". Delete all the rows before it.
>> > Step 2: Put cursor at end of file, Search for "Contact's Name:"
>> > select option UP.
>> > Step 3: Search for "Photo of the" Replace with blanks
>> > Step 4: Search for "Contact is" Replace with blanks
>> > Step 5: Search for "Contact's Name:" Replace with blanks
>> > Step 6: Search for "Age:" Replace with blanks
>> > Step 7: Search for "Sex:" Replace with blanks
>> > Step 8: Search for "House No:" Replace with blanks
>> > Step 9: Search for "available" Replace with blanks
>> > Step 10: Remove Empty Lines Containing Blank Characters from file
>> > Step 11: Trim Leading Space for each line
>> > Step 12: Trim Trailing Space after each line
>> > Step 13: Search for - (hyphen) Replace with _ (underscore)
>>
>> > Step 14: Save file.
>>
>> something like (untested)
>>
>>
>> import glob, codecs, re, os
>>
>> regex = re.compile(r"Age: |Sex: |House No: ") # etc etc
>>
>> for txt in glob.glob("/some/path/*.txt"):
>> with codecs.open(txt, encoding="utf-8") as f:
>> oldlines = f.readlines()
>> for i, line in enumerate(oldlines):
>> if "Contact's Name: " in line:
>> break
>> newlines = [regex.sub("", line).strip().replace("-", "_") for line in
>> oldlines[i:]
>> with codecs.open(txt + "_out.txt", "wb", encoding="utf-8") as w:
>> w.write(os.linesep.join(newlines))
>>
>>
>>
>>
>> >
>> > Currently I have recorded a macro in Notepad++.
>> > I open each file, run macro and save file.
>> > As there are many files I was looking for a program to automate the
>> process.
>> >
>> > I posted the same query in Notepad++ forum. I got a reply that it can
>> be done by
>> > using Python script.
>> >
>> > Kindly do the needful.
>> >
>> > Thank you.
>> > khalidness
>> >
>> > --
>> > https://mail.python.org/mailman/listinfo/python-list
>> >
>>
>
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python script that does batch find and replace in txt files

2014-11-09 Thread Syed Khalid
Albert,

Thanks a million for script,

It worked fine after I closed the bracket.


import glob, codecs, re, os

regex = re.compile(r"Age: |Sex: |House No:  ") # etc etc

for txt in glob.glob("D:/Python/source/*.txt"):
with codecs.open(txt, encoding="utf-8") as f:
oldlines = f.readlines()
for i, line in enumerate(oldlines):
if "Elector's Name:" in line:
break
newlines = [regex.sub("", line).strip().replace("-", "_") for line in
oldlines[i:]]
with codecs.open(txt + "_out.txt", "wb", encoding="utf-8") as w:
w.write(os.linesep.join(newlines))


This program is not deleting the empty lines containing blank characters.
Kindly do the needful.


On Mon, Nov 10, 2014 at 2:50 AM, Syed Khalid  wrote:

>
> Code after adding path of .txt files :
>
> import glob, codecs, re, os
>
> regex = re.compile(r"Age: |Sex: |House No: ") # etc etc
>
> for txt in glob.glob("D:/Python/source/*.txt"):
> with codecs.open(txt, encoding="utf-8") as f:
> oldlines = f.readlines()
> for i, line in enumerate(oldlines):
> if "Elector's Name:" in line:
> break
> newlines = [regex.sub("", line).strip().replace("-", "_") for line in
> oldlines[i:]
> with codecs.open(txt + "_out.txt", "wb", encoding="utf-8") as w:
> w.write(os.linesep.join(newlines))
>
>
> I executed code in edit rocket.
>
> Error message :
>
>
> File "EamClean.log", line 12
> with codecs.open(txt + "_out.txt", "wb", encoding="utf-8") as w:
>^
> SyntaxError: invalid syntax
>
>
>
>
>
> On Mon, Nov 10, 2014 at 2:22 AM, Syed Khalid  wrote:
>
>> Hi Albert,
>>
>> Thank you for script.
>>
>> I am getting the below error :
>>
>>   File "EamClean.log", line 12
>> with codecs.open(txt + "_out.txt", "wb", encoding="utf-8") as w:
>>^
>> SyntaxError: invalid syntax
>>
>> Kindly do the needful.
>>
>> On Mon, Nov 10, 2014 at 1:53 AM, Albert-Jan Roskam 
>> wrote:
>>
>>>
>>>
>>>
>>>
>>> - Original Message -
>>> > From: Syed Khalid 
>>> > To: python-list@python.org
>>> > Cc:
>>> > Sent: Sunday, November 9, 2014 8:58 PM
>>> > Subject: Python script that does batch find and replace in txt files
>>> >
>>> > Python script that does batch find and replace in txt files Need a
>>> python script
>>> > that opens all .txt files in a folder find replace/delete text and
>>> save files.
>>> >
>>> > I have text files and I need to perform below steps for each file.
>>> >
>>> > Step 1: Put cursor at start of file and Search for "Contact's
>>> > Name:". Delete all the rows before it.
>>> > Step 2: Put cursor at end of file, Search for "Contact's Name:"
>>> > select option UP.
>>> > Step 3: Search for "Photo of the" Replace with blanks
>>> > Step 4: Search for "Contact is" Replace with blanks
>>> > Step 5: Search for "Contact's Name:" Replace with blanks
>>> > Step 6: Search for "Age:" Replace with blanks
>>> > Step 7: Search for "Sex:" Replace with blanks
>>> > Step 8: Search for "House No:" Replace with blanks
>>> > Step 9: Search for "available" Replace with blanks
>>> > Step 10: Remove Empty Lines Containing Blank Characters from file
>>> > Step 11: Trim Leading Space for each line
>>> > Step 12: Trim Trailing Space after each line
>>> > Step 13: Search for - (hyphen) Replace with _ (underscore)
>>>
>>> > Step 14: Save file.
>>>
>>> something like (untested)
>>>
>>>
>>> import glob, codecs, re, os
>>>
>>> regex = re.compile(r"Age: |Sex: |House No: ") # etc etc
>>>
>>> for txt in glob.glob("/some/path/*.txt"):
>>> with codecs.open(txt, encoding="utf-8") as f:
>>> oldlines = f.readlines()
>>> for i, line in enumerate(oldlines):
>>> if "Contact's Name: " in line:
>>> break
>>> newlines = [regex.sub("", line).strip().replace("-", "_") for line
>>> in oldlines[i:]
>>> with codecs.open(txt + "_out.txt", "wb", encoding="utf-8") as w:
>>> w.write(os.linesep.join(newlines))
>>>
>>>
>>>
>>>
>>> >
>>> > Currently I have recorded a macro in Notepad++.
>>> > I open each file, run macro and save file.
>>> > As there are many files I was looking for a program to automate the
>>> process.
>>> >
>>> > I posted the same query in Notepad++ forum. I got a reply that it can
>>> be done by
>>> > using Python script.
>>> >
>>> > Kindly do the needful.
>>> >
>>> > Thank you.
>>> > khalidness
>>> >
>>> > --
>>> > https://mail.python.org/mailman/listinfo/python-list
>>> >
>>>
>>
>>
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python script that does batch find and replace in txt files

2014-11-09 Thread Syed Khalid
Albert,

Code is not removing  empty lines containing blank characters and not removing 
leading and trailing spaces present in each line. 




import glob, codecs, re, os

regex = re.compile(r"Age: |Sex: |House No:  ") # etc etc

for txt in glob.glob("D:/Python/source/*.txt"):   
with codecs.open(txt, encoding="utf-8") as f:
oldlines = f.readlines()
for i, line in enumerate(oldlines):
if "Elector's Name:" in line:
break
newlines = [regex.sub("", line).strip().replace("-", "_") for line in 
oldlines[i:]]
with codecs.open(txt + "_out.txt", "wb", encoding="utf-8") as w:
w.write(os.linesep.join(newlines))

Kindly do the needful
-- 
https://mail.python.org/mailman/listinfo/python-list


Indentation issues with python

2015-02-04 Thread syed khalid
 I downloaded this code and am attempting to run it. I keep getting
indentation error. there is a way to handle it with a editor which can
recognize the tab or space issue. I have tried different options such as 2
or 3 spaces or tab to no avail.

I have encased the error mesage with line 23 between ""

import sys
import azure
import socket

from azure.servicebus import (
_service_bus_error_handler
)

from azure.servicebus.servicebusservice import (
ServiceBusService,
ServiceBusSASAuthentication
)

from azure.http import (
HTTPRequest,
HTTPError
)

from azure.http.httpclient import _HTTPClient

class EventHubClient(object):
def sendMessage(self,body,partition):eventHubHost =
"pac-ns.servicebus.windows.net"
httpclient = _HTTPClient(service_instance=self)
 
File "test1.py", line 23
def sendMessage(self,body,partition):
^
IndentationError: expected an indented block
***
sasKeyName = "SendPolicy"
sasKeyValue = "erENqf/5wdWCNEbCA9NsDIRqd5MRKdkii07+wezl/NU="

authentication = ServiceBusSASAuthentication(sasKeyName,sasKeyValue)

request = HTTPRequest()
request.method = "POST"
request.host = eventHubHost
request.protocol_override = "https"
request.path = "/myhub/publishers/" + partition +
"/messages?api-version=2014-05
"
request.body = body
request.headers.append(('Content-Type',
'application/atom+xml;type=entry;charset
=utf-8'))

authentication.sign_request(request, httpclient)

request.headers.append(('Content-Length', str(len(request.body)))



-- 
*Syed Khalid*
-- 
https://mail.python.org/mailman/listinfo/python-list


Azure event hub network access

2015-02-05 Thread syed khalid
I am getting http error 404. I am able to access the site via telnet which
eliminates network issues. Here is the code and subsequent errors



user/bin/python
import sys
import azure
import socket

from azure.servicebus import (
  _service_bus_error_handler
  )

from azure.servicebus.servicebusservice import (
  ServiceBusService,
  ServiceBusSASAuthentication
  )

from azure.http import (
  HTTPRequest,
  HTTPError
  )

from azure.http.httpclient import _HTTPClient

class EventHubClient(object):

def sendMessage(self,body,partition):
eventHubHost = "pac-ns.servicebus.windows.net"

httpclient = _HTTPClient(service_instance=self)

sasKeyName = "pac-pl"
sasKeyValue = "IhkEepQPLfSy9jo6H2Y="

authentication = ServiceBusSASAuthentication(sasKeyName,sasKeyValue)

request = HTTPRequest()
request.method = "POST"
request.host = eventHubHost
request.protocol_override = "https"
#request.path = "/myhub/publishers/" + partition +
"/messages?api-version=20
14-05"
request.body = body
request.headers.append(('Content-Type',
'application/atom+xml;type=entry;cha
rset=utf-8'))

authentication.sign_request(request, httpclient)

request.headers.append(('Content-Length', str(len(request.body
status = 0

try:
resp = httpclient.perform_request(request)
status = resp.status
except HTTPError as ex:
status = ex.status

return status

class EventDataParser(object):

  def getMessage(self,payload,sensorId):
host = socket.gethostname()
body = "{ \"DeviceId\" : \"" + host + "\",\"SensorData\": [ "

msgs = payload.split(",")
first = True

for msg in msgs:
# print msg
  sensorType = msg.split(":")[0]
sensorValue = msg.split(":")[1]
  if first == True:
first = False
  else:
body += ","

  body += "{ \"SensorId\" : \"" + sensorId + "\", \"SensorType\" : \""
+ sen
sorType + "\", \"SensorValue\" : " + sensorValue + " }"
body += "]}"

return body

hubClient = EventHubClient()
parser = EventDataParser()
hostname = socket.gethostname()
sensor = sys.argv[2]

body = parser.getMessage(sys.argv[1],sensor)
hubStatus = hubClient.sendMessage(body,hostname)
# return the HTTP status to the caller
print hubStatus
print hostname
print sensor




~/IOT/AZURE$ python send.py temperature:22,humidity:20 deviceid

404
ubuntu
deviceid
{ "DeviceId" : "ubuntu","SensorData": [ { "SensorId" : "deviceid",
"SensorType" : "temperature", "SensorValue" : 22 },{ "SensorId" :
"deviceid", "SensorType" : "humidity", "SensorValue" : 20 }]}




-- 
*Syed Khalid*
-- 
https://mail.python.org/mailman/listinfo/python-list