Python

Python is a widely used general-purpose, high-level programming language. Its design philosophy emphasizes code readability, and its syntax allows programmers to express concepts in fewer lines of code than would be possible in other languages. Python supports multiple programming paradigms, including object-oriented, imperative and functional programming or procedural styles. It features a dynamic type system and automatic memory management and has a large and comprehensive set of standard libraries, including NumPy, SciPy, Django, PyQuery, and PyLibrary.

Share tech news, updates, or what's on your mind.

Sign up to Post

Hello,

I have below snmlwalk which I am trying to convert in python

$snmpwalk -v 2c -c my_Pa$$word lb.staging.com 1.3.6.1.4.1.5951.4.1.1.56.1.1.5.14.118.10.14.45.99.1.124.116.105.112.115.99.97.16.11
SNMPv2-SMI::enterprises.5951.4.1.1.56.1.1.5.14.118.10.14.45.99.1.124.116.105.112.115.99.97.16.11 = INTEGER: 4695

using pysnmp module I can a write the same in python, appreciate any guidance here, thanks!
0
On Demand Webinar: Networking for the Cloud Era
LVL 9
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.

hi,

i have a massive python project without Readme file. what is the best way to understand how to run that project?

many thanks.
0
Hello,
Back when C# came out; I did not know how to pronouns this combination of C and a # (sharp).  Talking to a  developer, he chuckled when I said "C pound."
And now, when "reading" about generic decorators; it is not written as to  how to pronouns these;
*args, **kwargs
Might any one have the phonetics /fəˈnediks/ on these two decorators;
*args, **kwargs

Thanks
0
I have a cheap Microsoft RFID reader from eBay.  I am using 125mhz chips.  I have a Python program that writes the card number and date to a text file on a server.  Groups of people scan their card and it writes each number and date on a new line in this text file.  Sometimes however, it writes a string of numbers all on the same line with just one date at the end.  Could the problem be that a delay should be written into the Python program between reading the card and writing it - say 100ms?
Each entry should be on a new line and look like this:

0268340542, , , , 11:28:41, 2017-06-07

I get a lot like the above and then it does the following:

026835201202683520560268339729026833971602683537820268339746026835368202683500370268351993026833974102683397410268350159026835013402683375290268350089026835203902683501050268350105, , , , 09:25:48, 2017-06-12

So instead of recording each RFID card it puts them all into the one line with one , , ,  , time and date at the end.
Someone has suggested that it is parallel writing and to lock the file between writes but I don’t know how to do this.
The code is below:
0
Hello everybody,
i wanna know what's the use of "yield" in python and what differentiates  it from "return"
0
We are using ELK(Elastic search, logstash, and Kibana) for our log management. Everytime I will export the setting from kibana UI from Management--->Save Objects--->Export Everything. For demo, one can checkout the url: Kibana Demo

cURL
I want to automate this export process with some scripting on linux. I tried CURL but the header/payload data looks to be dynamic and might have to update frequently. I want to try some web scraping techniques with some web automation tools like Selenium and pythion.

Selenium Webdriver
I tried to record this export action with Selenium IDE and from the IDE I exported the test plan/case into pythonkibana_python.py . As we click on Export Everything button on Kibana, a firefox window opens asking where to save. This action is not handled by selenium, meaning download file is not supported by selenium.

So, I'm looking for some scripting to export the json(Export Everything) file from Kibana UI and it mush be Headless as I would be scheduling this script in linux server. To be headless, I also tried phantomjs, but even this doesn't support file download.

Simply, I just want a script to automate clicking export everything button on kibana and want it be saved in a file. Please share your thoughts or any idea,  i'm trying this for days...
0
Hi All,

I have written a short program to read  a private Microsoft Message Queue and reformat the data to make it more
legible and store it in a file with a filename identifying the part or assembly. This code is part of a system to keep people informed about engineering changes to SolidWorks PDM Works files.

The problem I am having is that the command I am using to read the queue (queue.Receive()) blocks.

I have been unable to set the timeout or remove the block. The code compiles -- whatever that means for an interpretive language (using Geany) --- and runs.

It processes all the information correctly and generates the files as designed to do until the queue is empty.  Then it hangs (blocks) and waits for another message to arrive in the queue.

I want it to process all the messages in the queue and then exit.

I will set a trigger to run the program again when the private queue receives more messages.

Along the lines of this problem, is the import command and missing attributes and methods. For example, I import queue and queue.qsize(), queue.empty() and some others are missing. I saw that qsize and empty might be eliminated.

 However, I looked at queue.py and could not find  Receive. I was hoping to find the structure of Receive and figure out how to set the timeout and block.

No luck,

I  have attached the py file.

Thanks in advance for the help,

Andre'
PDM-Update-Reader.py
0
Hi.
I converted  dex reader code sample  from the python  example Python version  to java but i am failing on   master handshake (after slave in master mode).
Failed on State 3 - Sending master key.
Have some one experience to read audit data from DEX  vending machine from android Bluetooth or DEX  cable.
File Provided.
My task: Allows the user to read DEX from a vending machine using a Bluetooth DEX device.
DexReader.java
0
So i'm trying to parse some xml with ElementTree, but it's got smileys in what seems to be UTF-16 decimal.
it's got this `&#55357;&#56835;` in it but says it's UTF-8 in the <?xml?> tag.


How do I decode UTF-16? Is that the right question to ask?
0
Update: Found my own solution, but would prefer a tal: solution if there is instead of javascript

I am running Plone 5, and have created two content types:
1. Purchase Order
2. Purchase Order Details.

I have created a purchase order custom page template which includes information about the selected Purchase Order (Title/Summary), and a table with the Purchase Order Details (Item Description/Item Summary/Quantity/Cost/SubTotal) as pictured below.  I am struggling with how to calculate the total of the purchase order in this scenario.  In the code below I only initialize a value of 0, but need to add the code to increase the total after every iteration of the purchase order details.

Purchase Order Content Type Page Template
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"
      xmlns:tal="http://xml.zope.org/namespaces/tal"
      xmlns:metal="http://xml.zope.org/namespaces/metal"
      xmlns:i18n="http://xml.zope.org/namespaces/i18n"
      lang="en"
      metal:use-macro="context/main_template/macros/master"
      i18n:domain="plone">

<metal:css fill-slot="style_slot">
<style type="text/css">
    <!-- Replace this with your views' custom CSS -->
</style>
</metal:css>

<metal:javascript fill-slot="javascript_head_slot">
<script type="text/javascript">
jQuery(function($) {
    // Replace this with your view's custom onLoad-jQuery-code.
});
</script>
</metal:javascript>

<body>

<metal:content-core fill-slot="content-core">
    <metal:content-core 

Open in new window

0
Free Tool: Path Explorer
LVL 9
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

hi,

how do i install and run a python project from getlib on my mac computer?

thanks.
0
I have a cheap Microsoft RFID reader from eBay.  I am using 125mhz chips.  I have a Python program that writes the card number and date to a text file on a server.  Groups of people scan their card and it writes each number and date on a new line in this text file.  Sometimes however, it writes a string of numbers all on the same line with just one date at the end.  Could the problem be that a delay should be written into the Python program between reading the card and writing it - say 100ms?
0
Hi everyone,

So I've spent the past week reading and trying to understand the python language and more importantly the CherryPy web framework.
To be honest Im getting no-where quickly...

What I'm trying to do is simply build a frontend to a Raspberry Pi project I've been developing.
The CherryPy web framework seems perfect for this as it is small and contains its own web server that would suite my needs perfectly.

An admin user attaches to the Raspberry PI AP and is immediately directed to a webpage (This I have solved quite easily).
The webpage is presented by the CherryPy web server.

I have an index.html which it returned from my CherryPy script.

import os, os.path, sys
import cherrypy

# Configuration file to access server over network and define ports
cherrypy.config.update("server.conf")

class menu(object):
    @cherrypy.expose
    def index(self):
        return open('index.html')

(Fairly simply until now I know)

What I would like to do is have buttons on my index.html that can be pressed and return os.system('mkdir boom')  (obviously my system commands will be a little more than this.. They will start and stop services.

The buttons will eventually be toggle switches, so going to the page will need to return the current status of the running process. Red if the process is not running and Green if it is running. I think I need to be interacting with jquery on my index.html page to achieve this...

This whole area is new to me and …
0
I have a txt file containing data in following format:

abc 123 456
cde 45 32
efg 322 654
abc 445 856
cde 65 21
efg 147 384
abc 815 078
efg 843 286
and so on. How can transpose it into following format using Python:

abc 123 456 cde 45 32 efg 322 654
abc 445 856 cde 65 21 efg 147 348
abc 815 078 efg 843 286
Also, in case cde/efg is missing after abc, it should insert blank spaces instead, since it is a fixed width file.
One more thing , abc will always be present, sometimes row starting with cde or efg will not be there .
0
Hi,

I'm looking to use the GoogleFinance module
https://github.com/hongtaocai/googlefinance

to record the stock price every few minutes into a MySQL database

From the documentation I can see that it will require a list of stocks  - that I will keep in csv file

I'm having difficulty parsing the JSON that comes back in order read it into a variable.
'TypeError: list indices must be integers, not str'

Can anyone direct me to some resources that might give me a steer on how best to achieve this?

I will look to create a table for each stock being tracked
0
Hi,

Im been using Scapy for 2 months and is a very good piece of software... I been able to do all other things beside this one.

I want to send an RTS package and receive an CTS.

--------------------ENVIROMENT---------------------
$lsb_release
LSB Version:      core-9.20160110ubuntu0.2-amd64:core-9.20160110ubuntu0.2-noarch:security-9.20160110ubuntu0.2-amd64:security-9.20160110ubuntu0.2-noarch

$uname -a
Linux EDUARDO 4.4.0-81-generic #104-Ubuntu SMP Wed Jun 14 08:17:06 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

$ dpkg -l | grep scapy
ii  python-scapy                                                2.2.0-1                                       all          Packet ge...

$ python --version
Python 2.7.12

2 x Alfa Wireless AWUS036NH Cards

--------------------PROBLEM and TESTING Scenario---------------------

I want to be able to see the responses in Wireshark, by sending an RTS/Scapy in one Alfa card and receiving RTS+CTS in Wireshark in another.

How can this be achieved?

Eduardo

--------------------CODE---------------------
import datetime
from scapy.all import *
from scapy.all import Dot11,Dot11Beacon,Dot11Elt,RadioTap,sendp

ifacx="mon1"

addr1='60:a4:d0:21:fa:3c'
addr2='22:2B:22:23:22:22'
addr3='33:3B:43:33:33:33'

i=1
while 1:
    time.sleep(.100)
    i = i + 1

    #Send RTS
    Doto11 = Dot11(type=1,subtype=11,addr1=addr1,addr2=addr2,addr3=addr3,ID=0x99)
    pkt = RadioTap()/Doto11
    sendp(pkt,iface=ifacx,realtime=True)
 …
0
I am in the process of moving legacy codes in c to Intel 64 (ksh) from Unix Tru64 (ksh).  
 I created a basic hello world application in c so I could setup the debugger.   INTEL has instructed me to use the gdb-ia debugger.   I don't know where any manuals are to read this for myself.   I have gotten a few errors along the way that have lead me to add the following lines to my ksh users .profile.  
 export LD_LIBRARY_PATH=/opt/intel/debugger_2017/libipt/intel64/lib
 export PYTHONHOME=/usr
 Currently I am getting an error:  $>gdb-ia ImportError: No module named site
 With every question I ask INTEL, it takes me a business day to get an answer.  So, I've had great luck with Experts Exchange in the past, so I'm back to get some direction.  
 My last correspondence with INTEL was:  
      "Looks like you forgot to source the environment."
        "#source /opt/intel/bin/compilervars.sh intel64"

 Where am I going to add this line of code?   The "#source" makes me think it would go into an include file somewhere.   Can anyone see through this and give me some advice???
 I also have another post out there for mapping Tru64 compiler options to INTEL.  

 Thanks everyone for your help!
0
For a program i have nearly ready i need some code what i can't find in VB, only in Python.

import serial
import operator

def ibisString( str ):
bytestring = str+" "
bits = chr(0x7f) + bytestring
checksum = reduce(lambda x,y:chr((ord(x)^ord(y))&0xff),bits)
message = bytestring+checksum
output = map(lambda x:hex(ord(x)),message)
bytes = bytearray(int(x, 16) for x in output)
print output
return bytes

ser = serial.Serial(‘/dev/ttyUSB0‘, 1200, parity=‘E‘, stopbits=2, timeout=1)
ser.write(ibisString(‘l300‘))

Open in new window


Can anyone help me to convert this Python code to VB?
0
Hi all,

Need to write a python or shell script for email alert on memory utilisation of the server.
we are glance tool to monitor the cpu and memory utilisation for our weblogic servers. If the memory utilisation reached 80% it should alert us through mail so that we can check and restart if required.

below is the output of glance file
B0000A Glance C.04.70.000       04:56:38    x86_64                                                                     Current  Avg  High
------------------------------------------------------------------------------------------------------------------------------------------------------
CPU  Util   SU                                                                                                                       |  1%    3%   27%
Disk Util                                                                                                                            |  0%    0%    7%
Mem  Util   U                      UB     B                                                                                          | 26%   26%   26%
Swap Util                                                                                                                            |  0%    0%    0%
------------------------------------------------------------------------------------------------------------------------------------------------------
                                                                     PROCESS LIST                     …
0
[Webinar] Learn How Hackers Steal Your Credentials
LVL 9
[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

I have need of a context menu in Windows 7 Explorer that is essentially the "move to folder" command, but with a twist.

Instead of bringing up a dialog of where to move a file, I'd like to bring up a list.  The list would have three types of entries:
1) Recently visited folders
2) List of favorite folders (pinned)
3) Standard browse to folder

So, I have a few questions:

  1. Has this been done already?  If so, where can I get it?
  2. Where can I get Windows' recently visited folders programmatically?  If necessary, I can get these from recently used files, so where would I get the recently used files list programmatically?
  3. Is there any source code I can build off of which does something similar (preferably Python)?  If necessary: C++, C#,  Java?

Thanks!

I'm aware of the CodePlex source code for the MS examples, but they are long and pretty different from what I'm trying to acheive.
http://1code.codeplex.com/SourceControl/changeset/view/57974#Visual Studio 2010/VBShellExtContextMenuHandler/FileContextMenuExt.vb
0
I currently login to the time from website using the following script.


browser = webdriver.Chrome('E:/Shared Folders/Users/runnerjp/chromedriver/chromedriver.exe')
browser.get("https://www.timeform.com/horse-racing/account/sign-in?returnUrl=%2Fhorse-racing%2F") 
time.sleep(3)
username = browser.find_element_by_id("EmailAddress")
password = browser.find_element_by_id("Password")
username.send_keys("usr")
password.send_keys("pass")
login_attempt = browser.find_element_by_xpath("//input[@type='submit']")
time.sleep(3)
login_attempt.submit()

Open in new window


it works but I find using Chrome web driver is hammering my CPU. Is there an alternative code I could use that does not mean I need to physically load the page to sign in?
0
Please review below code, not able to copy config from device to tftp and vice versa
import paramiko
ssh = paramiko.SSHClient()

ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())

ssh.connect('192.168.1.12', port=22, username='cisco', password='cisco')

stdin, stdout, stderr = ssh.exec_command('copy tftp: flash: ')

stdin.write('192.168.1.10')

stdin.write('\n')

stdin.flush()

stdin.write('demotesting')
stdin.write('\n')
stdin.flush()

stdin.write('dest_demo')
stdin.write('\n')

output = stdout.readlines()
print '\n'.join(output)
ssh.close()

Open in new window


error :

L
ine has invalid autocommand "copy tftp: flash: "

Open in new window

0
I want to invoke a python script from my C++ app and get the data from the python script into my C++ app. How do I do this?

example: testing.py   reads data from and ADC -

C++ app - invoke testing.py  ; data = python testing.py
0
Im using python and paramiko. Im trying to backup a network device router using python. Below is my script. However im getting error

import paramiko
import sys
import time

HOST = "10.11.214.143"
USER = "admin"
PASS = "passwd"


client1=paramiko.SSHClient()
client1.set_missing_host_key_policy(paramiko.AutoAddPolicy())

client1.connect(HOST,username=USER,password=PASS)
  print "SSH connection to %s established" %HOST

#copying config to tftp
stdin, stdout, stderr = client1.exec_command('copy nvram:startup-config tftp: 10.11.214.144')
print stdout.read()


Traceback (most recent call last):
  File "<pyshell#12>", line 1, in <module>
    client1.exec_command('copy nvram:startup-config tftp:')
  File "C:\Python27\lib\site-packages\paramiko\client.py", line 436, in exec_command
    chan = self._transport.open_session(timeout=timeout)
  File "C:\Python27\lib\site-packages\paramiko\transport.py", line 716, in open_session
    timeout=timeout)
  File "C:\Python27\lib\site-packages\paramiko\transport.py", line 800, in open_channel
    raise SSHException('SSH session not active')
SSHException: SSH session not active

Open in new window

0
It seems I need to write an Inkscape extension to fill in names from a csv file and write the name on gravesites in cemetery lots.  There are about 100 lots with 12 gravesites per lot.  I could draw all of the names by hand but it seems like more fun to learn perl, python, and extensions.   Does anybody have any hints?
0

Python

Python is a widely used general-purpose, high-level programming language. Its design philosophy emphasizes code readability, and its syntax allows programmers to express concepts in fewer lines of code than would be possible in other languages. Python supports multiple programming paradigms, including object-oriented, imperative and functional programming or procedural styles. It features a dynamic type system and automatic memory management and has a large and comprehensive set of standard libraries, including NumPy, SciPy, Django, PyQuery, and PyLibrary.