Showing posts with label open python exe. Show all posts
Showing posts with label open python exe. Show all posts

Wednesday, November 30, 2011

Python String replace

I came across a point where the incoming user string had to be replaced with something i desire . Considering the simplicity of the activity i expected python to have some user defined function . might be a simple thing , but really useful...

replace( old , new, [max count]).
if you have the below
Code :
sample = "this is a test string"
print sample.replace("test" , "long test")
the result will look like this
"this is a long test string"
you dont have to import any library in specific.
the "max" from the syntax constitutes to the number of times the string has to be replaced.

Tuesday, November 29, 2011

Scan for bluetooth devices using python

scan for bluetooth devices using a python script. the below script can be used for performing the same. remember , you will have to install pybluez module (it is available for both windows and linux). now for the script , here you go!

import bluetooth

print "performing inquiry..."

nearby_devices = bluetooth.discover_devices(lookup_names = True)

print "found %d devices" % len(nearby_devices)

for addr, name in nearby_devices:
print " %s - %s" % (addr, name)


this will print the number of devices , address and name . this can be used as test script for a variety for reasons .

Tuesday, November 8, 2011

Open EXE with Python

I guess we all reach a point in our scripting space when we end up with opening an exe file from the script. Well , here the code for it . just replace the contents with the values you desire

import subprocess
import os
from win32api import ShellExecute
ShellExecute(0, "open","C:\\XXXX\\XXXX.exe","" , "C:\\XXX", 1)

There might be other ways of doing it , but i believe this one is simple enough for you to try.