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

There are 2 images in the pdf which i am trying to read,
1st is the logo.
2nd is the handwritten Sign.
The library is able to read the logo and convert to image using pillow.
but the issue comes when it tries to read the handwritten sign ,it spits out below error:
im = page.images[1].as_pil()
Traceback (most recent call last):

  File "<ipython-input-77-93f421217555>", line 1, in <module>
    im = page.images[1].as_pil()

  File "C:\Program Files\Anaconda3\lib\site-packages\minecart\content.py", line 363, in as_pil
    "Colorspace %r is not supported" % colorspace)

PDFNotImplementedError: Colorspace 'PDFObjRef:100>' is not supported

Open in new window

python version used : Python 3.5.2 :: Anaconda 4.2.0 (64-bit)
0
Introduction to Web Design
LVL 12
Introduction to Web Design

Develop a strong foundation and understanding of web design by learning HTML, CSS, and additional tools to help you develop your own website.

I have an interesting issue with Python Copying GeoData into a Shared drive on a unity400 SAN

arcpy.FeatureClassToFeatureClass_Conversion(sdeLayer.networkFGDB,"Test")

This Errros with Failed to execute (FeaturClassToFeatureClass) with Error 000210.

now the interesting part..  When running Process Monitor - This works fine - What could Process Monitor be doing?

I thought it may be creating a delay, between creating the Geo Data folder structure, and filling it,  so I have added a delay in the script.  
The only thing I can think of is it is either forcing something to close, or keeping something open, but I'm not sure how to check?  any ideas?
0
I have a python program -- and I am a terrible programmer -- that works but it is very slow because it takes a network address from a file and tries to find an address within that network from another file, so for each line in file A it reads through file B for every line in file A. There has to be a more efficient way to do this but I can't figure it out.

the vlans file looks like:
vlan10 testvlan 10.1.1.0/24
vlan11 devvlan 10.2.1.0/24

the hosts file looks like:
bob 10.1.1.3
ted 10.1.1.4
tom 10.2.1.4
tim 10.2.1.7

and the output needs to look like:
 
vlan10 testvlan 10.1.1.0/24 bob 10.1.1.3
vlan10 testvlan 10.1.1.0/24 ted 10.1.1.4
vlan11 devvlan 10.2.1.0/24 tom 10.2.1.4
vlan11 devvlan 10.2.1.0/24 tim 10.2.1.7

I need to read through the host file and find the ip address corresponding to the network in the vlan file.

In reality, the vlan file contains about 3000 vlans, and the host file contains 50,000 hosts.

This code works, but it is terribly inefficient. Also, I realized going back and forth between python2 (my linux box) and python3 (my windows box) there are issues with "unicode".

I would really appreciate some help.

Thanks,
Steve




#!/usr/bin/python 
import ipaddress

vlan = "/home/steve/vlp/vlans"
host = "/home/steve/vlp/hosts"

with open(vlan, "r") as vIN:
	for index, line in enumerate(vIN):
		var = line.split(' ')
		global net
		global netu
		net = unicode(var[2]).strip("\n")
		netu = ipaddress.ip_network(net)
#		

Open in new window

0
Hello Experts,

Can someone let me know where I can find practice questions on Python and SQL please? Particularly for beginners

Thanks
0
How can I use Python specifically tkinter to create a GUI to show a register of data from an MS Access table?

Thanks!
0
Hello Experts,

Can someone take a look at the following Python code and let me know why I'm getting the error:


TypeError: 'int' object is not iterable


list_sum = 0

for num in list_sum:
  list_sum = list_sum + sum
  
print(list_sum)

Open in new window


The full error message is as follows:


TypeError                                 Traceback (most recent call last)
<command-1972516025746490> in <module>()
      1 list_sum = 0
      2 
----> 3 for num in list_sum:
      4   list_sum = list_sum + sum
      5 

TypeError: 'int' object is not iterable

Open in new window

0
Hello Experts,

This questions requires someone with experience with Python and Databricks

A member from another forum assisted me in copying files to a follow based on date, https://stackoverflow.com/questions/54007074/how-to-truncate-and-or-use-wildcards-with-databrick

I would like to tweak the code to copy file based on certain characters in a filename – in the example that follows the characters are 1111, 1112, 1113 and 1114
So, if we have four files as follows:

File_Account_1111_exam1.csv
File_Account_1112_testxx.csv
File_Account_1113_pringle.csv
File_Account_1114_sam34.csv

I would like File_Account_1114_sam34.csv copied to the folder only if File_Account_1113_pringle.csv has already been copied to the folder.
Likewise I would only want File_Account_1113_pringle.csv copied  if File_Account_1112_testxx.csv has been already been copied to the folder and so on.

Therefore, if all files have been copied to a folder it would look like the following:

dbutils.fs.put("/mnt/adls2/demo/files/file_Account_1111_exam1.csv", data, True)
dbutils.fs.put("/mnt/adls2/demo/files/file_Account_1112_testxx.csv", data, True)
dbutils.fs.put("/mnt/adls2/demo/files/file_Account_1113_pringle.csv", data, True)
dbutils.fs.put("/mnt/adls2/demo/files/file_Account_1114_sam34.csv", data, True)

I appreciate there aren't many Experts with experience with Databricks on EE, however any help will be greatly appreciated.

Cheers
0
Hello Experts,

I'm not sure if there are many Databricks experts on this site, but I'll ask anyway.

I have written the following code in Databricks

dbutils.widgets.text("name", "Please Enter Your Name: ")
dbutils.widgets.text("age", "How old are you? ")
dbutils.widgets.text("guess", "Guess a Number")

name = dbutils.widgets.get("name")
age = int(dbutils.widgets.get("age"))
guess = int(dbutils.widgets.get("guess"))

print("Please guess a number between 1 and 10: ")
if guess < 5:
  print("Please guess higher")
  if guess == 5:
    print("Well Done, matey, you guessed it!")
  else:
    print("Bad luck you guessed incorrectly")

Open in new window


However, when I input 5 the number 5 the answer I get back is:

Please guess a number between 1 and 10:

However, I should get back the answer:

Well Done, matey, you guessed it

Can someone help figure out why
0
I was trying to setup Unetlab / Eve-Ng simulator for networking. I have installed and configured Eve however I’m stuck at adding images. I am getting error while trying to create iourc license with python script. Any help pls
0
I need to install Python 3 and PIP on a Redhat 7 Server in an environment with no direct Internet access, can you advise the best way to do this?
0
OWASP: Forgery and Phishing
LVL 12
OWASP: Forgery and Phishing

Learn the techniques to avoid forgery and phishing attacks and the types of attacks an application or network may face.

Hello Experts,

Can someone advise on applications that will generate Flow charts from Python code.

I looking for a tool is intelligent enough to convert code into logical flow.

Thanks

Carlton
0
Have 2 ubuntu installations on Oracle VM. They are in the same version. I ran the same python script against its own ubuntu in the exactly same way. Ran well on one, but got the error on the other one below:
"ModuleNotFoundError: No module named 'x'".
I knew the one without error was installed more packages, but I did not remember which more packages were installed. Under this condition, how to troubleshoot this issue? Can any gurus shed some light to it? Thanks a lot.
Background:
ubuntu 18.04 on VirtualBox V5.2.22 in Windows 7 (2 Ubuntus installed on the same box).
0
Running Windows 7 pro on an HP z230 computer.
I just installed Visual Studio Community edition.    I selected the option to install support for Python.  Two of the selections offered were to install Python v3.7 or Anconda 5.3.
I am a bit confused .   According to the www.anaconda.com website, it seems the most recent Anaconda version is 2018.12.

Q1.) What is the latest version of Anaconda?
Q2.) What is the best way to install Anaconda and use it with Visual Studio?
Q2.) What happens if I install Anaconda without installing Python v3.7 first?
0
I am want to ask some devops questions.
Where in Devops we us Python scripts.
0
I have a secondary question for Excel in the que trying to show in Real Time the elapsed time displayed after a time stamp is generated by the selection of a cell.

I am hoping to create a listing solution that shows something like this.

Priority Code           Question #      Time In        Item Code       Description         Special Instructions         Elapsed Time         Student    Table #      Time Out
ER                         11                    12:00:00       400               Math Q11      Student has LRN DIS     00:12:43                 Rob             3                  NA      If complete Time =12:12:43

1                            11                    12:02:23       400               Math Q11     Student Hear Impair     00:09:16                  Mary           5                  NA

2                            9                      12:01:47       398               Math Q9        Student Vis Impair        00:08:57                  Erica            4                  NA

If the Priority code entered is ER the row moves to the top of the list or if the Elapsed time is the highest priority It moves to the top of the list. So the point is if the value is manually changed in the Priority Code as ER it moves to the top row automatically. The Elapsed time is listed in descending order. This keeps instructors on top of who is struggling with whatever question is stopping most students or who has been given priority regardless of the elapsed time. Some students need priority help …
0
Content of my canvas looks like it is not in the canvas tkinter.
Here is the code:
from tkinter import *
root = Tk()
height = root.winfo_screenheight()
canvas = Canvas(root, bd=0,width=800,height=height,bg = "blue")
screen_fit = height/105
frame_number = 2
EDIT_QUESTIONS= Label(root,text="Edit questions",font = "Courier").grid(row = 1,column = 1)
class edit:
    def __init__(self):
       canvas.grid(row=2,column=2)
       self.new_frame()
    def new_frame(self):
        def remove(window):
            pass
        def new_frame1(self):
            global frame_number
            
            frame = Frame(root)
            r = (10 + 105)* (frame_number -1)
            frame_number =  frame_number + 1
            window = canvas.create_window(25, r , anchor = "nw", window = frame,tags =(frame_number))
            text = Text(frame,height = 2)
            text.grid(row=1,column=2)
            plus = Button(frame,text="+",command = self.new_frame)
            plus.grid(row=2,column=1)            
            minus = Button(frame,text="-" )
            #minus.config(command = lambda: remove(window))
            minus.grid(row=3,column=1)

            if frame_number > int(screen_fit)or frame_number == int(screen_fit):
                def on_mousewheel(event):
                    canvas.yview_scroll(-1*(int(event.delta/120)), "units") 

                scrollbar= Scrollbar(root,orient="vertical",command=canvas.yview)
                scrollbar.grid(row=2,column=4,sticky =

Open in new window

0
Have DRF View based on APIView , from which I'm getting queryset as a list of tuples.
I need to serialize this queryset and pass it to rest_framework.response.Response object as a result, i.e. serializer.data.
How should Serializer class look to accomplish this task?

class SomeView(APIView):

    def post:
        result = cursor.fetchall()
        serializer = SomeSerializer(result)
        return Response(serializer.data)

Open in new window


How should I render result in SomeSerializer class? Can you give me working implementation of that?

P.S. Thera are no any model related to these results in the system.
0
I am designing the game Othello or Reversegram as it is known in some places. I'm almost done coding the game save for tallying up the final score and tweaking the AI to make more intelligent moves (currently only doing random moves). However, I am encountering certain bugs that appear. While the CPU and I keep flipping the pieces, there will come some point where I either cannot make a move even though it is certainly legal to do so. As well as the fact that when I play certain moves usually around the edges, it sometimes won't flip the opposing pieces even though I just made a legal move. If I can get some help understanding where I should be making my edits--I think the error might be in the "findLegal" function. Thank you for your help!

Note: I recreated the board with W on 6b, and B on 7b and 8a and could make the legal move of W on 8b so vertical moves are generally accepted and work up until a certain point which I'm confused about. In addition, I originally set up the board in the picture with random pieces throughout to accelerate the game and also to test out the various issues I had (so please ignore the random W on 4h).
othello.py
Screen-Shot-2018-12-18-at-10.52.37-P.png
0
Hello All,
when running the below python script from the terminal to change an interface MAC, I get the following message: "siocsifhwaddr cannot assign requested address"

any ideas of what could be happening?

---------------------------------------------------------------------------------------------------------------------------------
#!/usr/bin/env python

import subprocess

interface = "eth0"
new_mac = "11:22:33:44:55:11"
print("[+] Changing MAC for " + interface + " to " + new_mac)

subprocess.call("ifconfig " + interface + " down", shell=True)
subprocess.call("ifconfig " + interface + " hw ether " + new_mac, shell=True)
subprocess.call("ifconfig " + interface + " up", shell=True)

-----------------------------------------------------------------------------------------------------------------------------------------
0
OWASP Proactive Controls
LVL 12
OWASP Proactive Controls

Learn the most important control and control categories that every architect and developer should include in their projects.

I need to read through 1000's of config files and get a list of all VLANs, their description and their IP address and mask. The data looks like:

interface Vlan100
  description Just a vlan
  no shutdown
  no ip redirects
  ip address 1.1.1.1/26

interface Vlan200
  description Just aother vlan
  no shutdown
  no ip redirects
  ip address 2.2.2.2/26

And there lots of other configuration data in the config file that I don't care about. What I have right now is a python program that opens the config file, and reads through looking for 3 strings: "interface Vlan", "  description", and "ip address". The problem, if you know Cisco, is that 2 of those strings occur in places other than vlan definitions.

I am trying to work through the logic of:

Find the line that contains "interface Vlan"
Write that line
and read the lines looking for "description" and "ip address" UNTIL I find another line that says "interface Vlan"

Make sense? I can run the python script now and then delete all the lines up until the first VLAN line and then delete all the lines afterword. But that will be very time consuming for all the files I have to work with.

Thanks in advance for your help.

Steve
0
Is it possible in Java to connect to the bitcoin.de websocket?
Here is Python 2.7 / Twisted
https://raw.githubusercontent.com/matthiaslinden/bitcoinDE_API/master/bitcoinDEws.py

It is hard to understand what exactly should be sent to bitcoin.de to make it upgrade to WebSocket.
0
I am trying to find a way to query the configuration of an Azure load Balancer using an API and either powershell or python script to populate two fields in the API, the ResourceGroup name and the Subscription ID. The output will need to be in a JSON or XML format.
0
Hi ..
I have template file as shown below:
locations total
building1 89.89
building2 678.45
building3 789.56
building4 45.90

Open in new window

I have python script that needs to read the template file and set values for the variables as shown below:

place1= is always the value on the second row of first column
number1 =  is always the value on the second row of second column
place2= is always the value on the 3rd row of first column
number2 =  is always the value on the 3rd row of second column
place3= is always the value on the 4rd row of first column
number3 =  is always the value on the 4rd row of second column
place4= is always the value on the 5rd row of first column
number4 =  is always the value on the 5rd row of second column

Open in new window


How can I read the file and set the variables in python.

Thanks.
0
Hi..
in a python script how can i get all the ip address of  the DNS servers on the network.

Thank you for your help.
0
I have a Tkinter application (python 2.7) that copies , configures , remove files. During this operation, I would like to pop up a please wait message box without any buttons while the process is running to inform the users What is the best way to do this.
Thank you for your Quick Prompts.
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.

Top Experts In
Python
<
Monthly
>