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

We are creating a kiosk device on Windows 10 Pro and need to pass keyboard input ( credentials ) into an application.  Zero interaction from users is required.
I have researched, python, vbs, batch, powershell scripts.
0
Keep up with what's happening at Experts Exchange!
LVL 12
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Hello, I recently started making programs in Python using pyautogui. Here is some of my code:
import pyautogui
while True:
    position = pyautogui.position()
    x = position[0:3]
    y = position[-3:]
    print(x,y)

Open in new window

But when I run the code it only prints a variable called  position two times on one line.
What should I do to print two independent variables? One holding the value of the first three digits of the variable position and the second one the last three digits of the variable position.
0
Hello, I need your advice in which program can i accomplish the following either with C# or Python.
I am a Sys Admin working for a DevOps environment.

We have QA, UAT and PROD environments.
100% of the the time we need to help developers in Copying, Pasting  From / To, Starting a service, Stopping a service and Recycling an app pool in IIS.
But in PROD night, we are done around 8pm, 1hr approx which includes: Copying, Pasting  From / To, Starting a service, Stopping a service and Recycling an app pool in IIS then we have to wait, wait wait and wait if the developers find any issues in PROD and they need the Sys Admin help for Copying, Pasting  From / To, Starting a service, Stopping a service and Recycling an app pool in IIS.

It was my first time that I experienced that and I said: Damn, the whole Copying, Pasting  From / To, Starting a service, Stopping a service and Recycling an app pool in IIS can done programmatically and we do not need to wait till midnight or so if Developers need a SysAdmin, in other words i can try to develop an executable that can do the following:

Which environment are you working: QA, UAT, PROD
Servers are listed: 1, 2, 3, 4
Which windows service are you going to work ? (List of services)
Browse the source, Get the file,.
Need to stop the service (Yes/No)
Browse to the target ? Place
This server has the following App Pools (List of the App Pools)
Do they need to be recycle ?

Thoughts ? Thanks for your help
0
How to protect and unprotect the excel sheet?
0
I am trying to write a python script that will search for a word in a file and execute a condition if the word was not found.

this is my code:

 searchfile = open("file_content", "r")
   for line in searchfile:
    if "word" not in line: print("word not found")
      else
    print "word found"

If the word was not found the result will display "word not found" number of times, equal to the number of lines available in the text file.
How can I print a single "word not found" only?
0
Dear experts,

Can anyone point to any online site which can has c/c++/Python programs written/used for Financial Engineering.

The idea is show the content/calculations involved in Financial Engineering to my tutor who can then teach me leading to building my fundamentals.

My tutors teaches for Engineering college students and may not have the orientation of Financial Engineering programming features/calculations.

Kindly guide.

Thank you
0
how rfid reader read uhf rfid tag using python language.........plz help mi
0
Hello, I am a beginner in Python and I started about a week ago.  I would like to continue with Python, but there is a problem: I successfully added Python to path, so I could open MS Powershell and then type py to get started with some features like downloading modules with pip.  As I was told, I need to add pip to my path too and make a new environment variable. I copied the exact location of the file in this way C:\Users\Myname\Downloads\get-pip (get-pip was name of the file after download). I also tried C:\Users\Myname\Downloads\get-pip.py. Both of these options did not work. Then I thought that I didn't download it correctly. So I started as they wrote on their official website. https://pip.pypa.io/en/stable/installing/ After the first step MS Powershell showed me the following Error:
curl : Požadavek byl přerušen: Nelze vytvořit zabezpečený kanál SSL/TLS..
At line:1 char:1
+ curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebExc
   eption
    + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
I use Windows 10. I would be very pleased, if you would answer me. If any additional information is needed,just tell me , I will try to do my best to provide it.
0
Cron job does not excute python. python runs in shell while it does not when specified under cron to run every minuts
I looked at internet for every posible solution but I get no result.

Followings are my configuration:
cron path
* * * * * /usr/bin/python /root/python/file.py

python environment variable
/usr/bin/python

file permission
-rwxrwxrwx. 1 root root   91 May 17 12:03 file.py

file.py file content
#!/usr/bin/python
f = open("demofile.txt", "a")
f.write("Now the file has one more line!")

python --version:     Python 2.6.6 | redhat 6.9



Thanks in advance
0
Hi experts,

I get bad gateway request.  I use nginx, uwsgi docker wagtail application.  Please find attached nginx.ini and uwsgi.ini  I am running all inside a docker containers.

nginx settings

user www-data;
worker_processes auto;
pid /run/nginx.pid;

events {
        worker_connections 768;
        # multi_accept on;
}

http {

        ##
        # Basic Settings
        ##

        sendfile on;
        tcp_nopush on;
        tcp_nodelay on;
        keepalive_timeout 65;
        types_hash_max_size 2048;
        # server_tokens off;

        # server_names_hash_bucket_size 64;
        # server_name_in_redirect off;

        include /etc/nginx/mime.types;
        default_type application/octet-stream;

        ##
        # SSL Settings
        ##

        ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
        ssl_prefer_server_ciphers on;

        ##
        # Logging Settings
        ##

        access_log /var/log/nginx/access.log;
        error_log /var/log/nginx/error.log;

        ##
        # Gzip Settings
        ##

        gzip on;
        gzip_disable "msie6";

        # gzip_vary on;
        # gzip_proxied any;
        # gzip_comp_level 6;
        # gzip_buffers 16 8k;
        # gzip_http_version 1.1;
        # gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;

        ##
        # Virtual Host Configs
        ##

        include 

Open in new window

0
Get expert help—faster!
LVL 12
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Hi Experts,

      I get the following error when I run python3 manage.py collectstatic.  Please see the error below.

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/dist-packages/debug_toolbar/toolbar.py", line 118, in get_panel_classes
    mod = import_module(panel_module)
  File "/usr/lib/python3.6/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 994, in _gcd_import
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 678, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/usr/local/lib/python3.6/dist-packages/debug_toolbar/panels/request.py", line 3, in <module>
    from django.core.urlresolvers import resolve
ModuleNotFoundError: No module named 'django.core.urlresolvers'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "manage.py", line 22, in <module>
    execute_from_command_line(sys.argv)
  File "/usr/local/lib/python3.6/dist-packages/django/core/management/__init__.py", line 371, in execute_from_command_line
    utility.execute()
  File 

Open in new window

0
import mysql.connector
from mysql.connector import Error
import os


db = mysql.connector.connect(host='localhost',database='mysql', user='root',password='admin@123')
cursor = db.cursor()

for root, dirs, files in os.walk('music'):
    # pref = ''
    head, tail = os.path.split(root)
    while head:
        # pref +='  '
        head, _tail = os.path.split(head)
      fname = os.path.join(tail)
      cursor.execute("INSERT INTO category(name,parent_id) VALUES('" + fname + "',1)")
      db.commit()
      print(head)

for f in dirs:
      print (f)



output:-
+-------------+----------+-----------+
| category_id | name     | parent_id |
+-------------+----------+-----------+
|           1 | rxl      |         1 |
|           2 | jazz     |         1 |
|           3 | del      |         1 |
|           4 | del      |         1 |
|           5 | mum      |         1 |
|           6 | mum      |         1 |
|           7 | jmv      |         1 |
|           8 | jmv      |         1 |
|           9 | jmv      |         1 |
|          10 | hip hop  |         1 |
|          11 | kol      |         1 |
|          12 | kol      |         1 |
|          13 | bang     |         1 |
|          14 | bang     |         1 |
|          15 | hyd      |         1 |
|          16 | hyd      |         1 |
|          17 | pop      |         1 |
+-------------+----------+-----------+
inserting dirs/subdir/files to mysql from python with parent id.here parent =music …
0
How to write python code that would find a biggest value from a file and print the line that hold that big value

example:
file.txt
10 172.1.1.1
200 172.1.1.2
3  172.1.1.3

The script should loop through file.txt find and select number 200 and print 200 172.1.1.2 to a file.

I have the following, but it only print the first number 200

max_num = 0
with open('file.txt', 'r') as data: # use the with context so that the file closes gracefully
  for line in data.readlines(): # read the lines as a generator to be nice to my memory

    val = int(line.split()[0])
    if val > max_num: # logic
     max_num = val
print max_num #result
0
When I try to run the below script as python3.6 prog5.py 4 -v 1, I just get the value of the answer but not the output of print ("{}^2 == {}".format (args.square, answer)). Same thing with a value of 2

#!/usr/local/bin/python3.6

import argparse
parser = argparse.ArgumentParser()
parser.add_argument("square", type=int, help="display a square of a given number")
parser.add_argument("-v", "--verbosity",help="increase verbosity output")
args = parser.parse_args()
answer = args.square**2
if args.verbosity == 2:
    print("the square of {} equals {}".format(args.square, answer))
elif args.verbosity == 1:
    print ("{}^2 == {}".format (args.square, answer))
else:
    print(answer)
0
I am learning python and see the below line of code. I would like to know what it means

print("%.*f" % (digits, pi))

Here is the full code to return the value of pi up to first 10 digits.

Thanks
AB
0
How do I count repetitive consecutive two words from a text file.

input.txt file contains

backend error oracle error insufficient space
oracle error
insufficient space insufficient space
complete order etc

output should be
backend error count 1
oracle error count  2
insufficient space count 3
complete order 1
etc 1
0
Run command using ansible on appliances with restricted bash
0
I have over 10 Amazon Ec2 Instances running and I want to automate their backups to a Amazon S3 Bucket. I have been told that I can do this using a Amazon Linux AMI with python code but I am unsure how to accomplish this.

Could someone please provide me a simple solution on how to accomplish this, specifically in python code.

Thank you for your time.
0
To delete the first column from excel sheet.
Like to delete Column "A" and re-write the data from Column A which is previously from Column "B".
Can we do that using Python?
0
Cloud Class® Course: CompTIA Healthcare IT Tech
LVL 12
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

While running Django Project run server getting Bad Magic Error.How can I solve the Problem ? Using python2 and Django 1.8 Screenshot-from-2018-05-09-23-40-49.png
0
Hi

I already asked a dragging question, but didn't ask about not leaving a trail of smudged pixels.
For anyone curious,
This is the stack overflow page i'm using for my Pygame mouse select, mouse-down and drag.

 here

My strategy for smooth dragging over existing pieces is...
On a piece select,
1) paste a blank square over that  piece, to clear its start off space,
2) Remember the x,y click displacement from the top left of the piece square, to help maintain the location of the piece as it is dragged under the cursor.
2) Capture the region under the mouse cursor to be repasted once the piece is dragged to cover up the old piece image. Can I save and re-paste the entire screen, super fast way? Redraw would be 2 slow.
Is the double buffing automatic? SetActivePage? setVisualPage()?

Thanks
0
I'm new to IBM Watson. I have to do natural language classification in python using Watson NLC. Can you please suggest some learning resources which will help me to learn NLC in python from scratch?
0
I'm trying to find the equation of motions for a inverted pendulum on a cart using Lagrangian method in Sympy . I checked the examples on GitHub and wrote the code below but after running  "form_lagranges_equations() " method I receive this error :



 sympy/core/function.py", line 1113, in __new__    Can\'t calculate %s%s derivative wrt %s.''' % (count, ordinal,
v)))
ValueError:Can't calculate 1st derivative wrt 1.

My Code :
# coding: utf-8


from __future__ import division, print_function
import sympy as sm
from sympy import trigsimp
import sympy.physics.mechanics as me
import mpmath as mp

#from sympy.physics.vector import init_vprinting, vlatex
#init_vprinting(use_latex='mathjax', pretty_print=False)

q = me.dynamicsymbols('q:2')
qdot = me.dynamicsymbols('q:2', 1)
f = me.dynamicsymbols('f')
m = sm.symbols('m:2')
J = sm.symbols('J:2')
l = sm.symbols('l')
a = sm.symbols('a')
d = sm.symbols('d')
g, t = sm.symbols('g t')

In_frame = me.ReferenceFrame('In_frame')
O = me.Point('O')
O.set_vel(In_frame, 0)

C0 = me.Point('C0')
C0.set_pos(O, q[0] * In_frame.x)
C0.set_vel(In_frame, qdot[0] * In_frame.x)

cart_frame = In_frame.orientnew('L0', 'Axis', [q[0], In_frame.x])
cart_frame.set_ang_vel(In_frame, 0)

cart_inertia_dyadic = me.inertia(cart_frame, 0, 0, J[0])
cart_central_inertia = (cart_inertia_dyadic, C0)

cart = me.RigidBody('Cart', C0, cart_frame, m[0], cart_central_inertia)

pen_frame = In_frame.orientnew('L1', 'Axis', [q[1], 

Open in new window

0
Hi
My Python chess GUI is coming on well.
The 8x8, black and white is perfectly structured, colored at a changeable square_size

The white squares are just the white window background.
However, my transparent pieces don't render on a black square (rectangle draw.rect)
They are pasted under it! I can move the piece location by a few pixels, and see it emerge slowly from under the black square.

Is this a known issue?

Here is my relevant code, there is no code between them

pygame.draw.rect(screen, square_color, (x*square_size,y*square_size,square_size,square_size), 0)
       
            screen.blit(white_king,(x*square_size,y*square_size))

Open in new window

Thanks
0
Hi,
I'd like to implement an AGI function for asterisk using the Jack() application in order to inject audio in, and stream audio out to another application but I'm no able to find any example, preferencibly in python.
Anyone, can help?

Thanks,
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.