Dev Shed Forums - Python Programming http://forums.devshed.com/ Python Programming forum discussing coding techniques, tips and tricks, and Zope related information. Python was designed from the ground up to be a completely object-oriented programming language. en Sun, 19 Nov 2017 01:09:14 GMT vBulletin 60 http://forums.devshed.com/images/misc/rss.png Dev Shed Forums - Python Programming http://forums.devshed.com/ Oanda Api for price streaming http://forums.devshed.com/python-programming/979424-oanda-api-price-streaming-new-post.html Fri, 10 Nov 2017 14:56:07 GMT Hello everyone I am not sure if this is the right place to ask questions if not please refer me to the right place and I will move my question there . I am trying to make GUI application and implement Oanda API in it so I can stream forex pairs prices in my own GUI using matplotlib. I have everything set but the problem is I don't know how to retrieve the data using their API and most of the documentations on the net is all about algo trading , but what I am interested about at this point is to get instruments prices and stream them in my own GUI can anyone help me please on this? I m doing it to learn python ]]> Python Programming beforcoffe http://forums.devshed.com/python-programming-11/oanda-api-price-streaming-979424.html python CSV http://forums.devshed.com/python-programming/979400-python-csv-new-post.html Tue, 07 Nov 2017 19:35:26 GMT I need to download the printed thread to a CSV file how do I do it?   Code: --------- from urllib.request import urlopen as uReq from bs4 import BeautifulSoup as soup import urllib I need to download the printed thread to a CSV file
how do I do it?

 
Code:

from urllib.request import urlopen as uReq
from bs4 import BeautifulSoup as soup
import urllib

my_url ='http://www.telesport.co.il/%D7%90%D7%96%D7%95%D7%A8%20%D7%95%D7%95%D7%99%D7%A0%D7%A8'
uClient = uReq(my_url)
page_html = uClient.read()
uClient.close()
page_soup = soup(page_html, "html.parser")

cc = page_soup.findAll("td",{"class":"th_td_WinnerteamsAndBetType"})

for i in range(10):
    print(cc[0+i].text, i)

]]>
Python Programming davidc8 http://forums.devshed.com/python-programming-11/python-csv-979400.html
Brand new to Python http://forums.devshed.com/python-programming/979381-brand-python-new-post.html Sat, 04 Nov 2017 02:08:00 GMT Brand new to coding and Python just saying hello! Brand new to coding and Python just saying hello! ]]> Python Programming mmaynard http://forums.devshed.com/python-programming-11/brand-python-979381.html Python dezoomify challenging code http://forums.devshed.com/python-programming/979366-python-dezoomify-challenging-code-new-post.html Thu, 02 Nov 2017 13:22:28 GMT Hello, I tried to use dezoomify code (from Github). The code allow to download extra-large images -with sample image: all works fine. -with desired image from BIOMAX: error -using Microsoft edge to download via ophir site (online dezoomer): only 30% of the file was downloaded and then it stopped, probably the file is to large. -also tried all advises in github, wiki, sourcefrog etc. ... Hello,
I tried to use dezoomify code (from Github).
The code allow to download extra-large images
-with sample image: all works fine.
-with desired image from BIOMAX: error
-using Microsoft edge to download via ophir site (online dezoomer): only 30% of the file was downloaded and then it stopped, probably the file is to large.
-also tried all advises in github, wiki, sourcefrog etc.
when running the code it gives the error: Zoomify base directory not found. Ensure the given URL contains a Zoomify object.
the desired image located at the following link:
https://www.biomax.us/index.php?rout...ify&park=31058

I have no permission to attache file, so I'll post the code as reply to this post.

Can someone help me solve this complicated challenge?

Thanks! ]]>
Python Programming Ezra Ezra http://forums.devshed.com/python-programming-11/python-dezoomify-challenging-code-979366.html
<![CDATA[[JCads Converter] Error Found !...]]> http://forums.devshed.com/python-programming/979331-jcads-converter-error-found-new-post.html Thu, 26 Oct 2017 19:33:31 GMT Hey Python Programmers... I try to create an simple program they can convert images to other images. Now i get an error from python if you fails with typ your image file... This is my script, i use PILLOW in python 3.6.2: Code: --------- # JCads Texturics - Converter Hey Python Programmers...

I try to create an simple program they can convert images to other images.
Now i get an error from python if you fails with typ your image file...

This is my script, i use PILLOW in python 3.6.2:
Code:

# JCads Texturics - Converter
# ---------------------------
# Made by Jamie van Cadsand
from PIL import Image
import time




print("")
print("JCADS TEXTURICS / CONVERTER:")
print("")
print("")


# Define Defeult_Converting
def ConvertToDefeult():
    print("")
    try:
        defeultImage = Image.open(input("Load Image: ")).convert('RGB')

        defeult = str(input("Press 'P' to Preview or 'S' to Save: "))
        if(defeult == "P"):
            defeult = "P"
            defeultImage.show()
            print("")
            print("Image Preview")
            print("")

            quitJCads = str(input("Press any key to Quit: "))
            if(quitJCads == "Q"):
                quitJCads = "Q"

                print("")
                print("Quit JCads...")
                time.sleep(1)
                quit()

            else:
                print("")
                print("Quit JCads...")
                time.sleep(1)
                quit()

        elif(defeult == "S"):
            defeult = "S"
           
            try:
                defeultImage.save(input("Brouse Image: "))
                print("")
                time.sleep(1)
                print("Succesfully Saved...")

                print("")
                print("Quit JCads...")
                time.sleep(1)
                quit()

            except IOError:
                print("")
                print("File not Found...")
                print("")

                print("Quit JCads...")
                time.sleep(1)
                quit()

        else:
            print("")
            print("Only press 'P' or 'S'...")
            print("")

            print("Quit JCads...")
            time.sleep(1)
            quit()


    except IOError:
        print("")
        print("File not Found")
       
       
       



# Define Defeult_Converting
def ConvertToTransparant():
    print("")
    try:
        defeultImage = Image.open(input("Load Image: ")).convert('RGBA')

        defeult = str(input("Press 'P' to Preview or 'S' to Save: "))
        if(defeult == "P"):
            defeult = "P"
            defeultImage.show()
            print("")
            print("Image Preview")
            print("")

            quitJCads = str(input("Press any key to Quit: "))
            if(quitJCads == "Q"):
                quitJCads = "Q"

                print("")
                print("Quit JCads...")
                time.sleep(1)
                quit()

            else:
                print("")
                print("Quit JCads...")
                time.sleep(1)
                quit()

        elif(defeult == "S"):
            defeult = "S"
           
            try:
                defeultImage.save(input("Brouse Image: "))
                print("")
                time.sleep(1)
                print("Succesfully Saved...")

                print("")
                print("Quit JCads...")
                time.sleep(1)
                quit()

            except IOError:
                print("")
                print("File not Found...")
                print("")

                print("Quit JCads...")
                time.sleep(1)
                quit()

        else:
            print("")
            print("Only press 'P' or 'S'...")
            print("")

            print("Quit JCads...")
            time.sleep(1)
            quit()


    except IOError:
        print("")
        print("File not Found")


       

# Define Defeult_Converting
def ConvertToGrayscale():
    print("")
    try:
        defeultImage = Image.open(input("Load Image: ")).convert('L')

        defeult = str(input("Press 'P' to Preview or 'S' to Save: "))
        if(defeult == "P"):
            defeult = "P"
            defeultImage.show()
            print("")
            print("Image Preview")
            print("")

            quitJCads = str(input("Press any key to Quit: "))
            if(quitJCads == "Q"):
                quitJCads = "Q"

                print("")
                print("Quit JCads...")
                time.sleep(1)
                quit()

            else:
                print("")
                print("Quit JCads...")
                time.sleep(1)
                quit()

        elif(defeult == "S"):
            defeult = "S"
           
            try:
                defeultImage.save(input("Brouse Image: "))
                print("")
                time.sleep(1)
                print("Succesfully Saved...")

                print("")
                print("Quit JCads...")
                time.sleep(1)
                quit()

            except IOError:
                print("")
                print("File not Found...")
                print("")

                print("Quit JCads...")
                time.sleep(1)
                quit()

        else:
            print("")
            print("Only press 'P' or 'S'...")
            print("")

            print("Quit JCads...")
            time.sleep(1)
            quit()


    except IOError:
        print("")
        print("File not Found")








       
# Define Project Starter
def startProject():
    img2assent = str(input("Converter Type: "))
    if(img2assent == "Defeult"):
        img2assent = "Defeult"
        ConvertToDefeult()
    elif(img2assent == "Transparant"):
        img2assent = "Transparant"
        ConvertToTransparant()
    elif(img2assent == "Grayscale"):
        img2assent = "Grayscale"
        ConvertToGrayscale()
    else:
        print("")
        print("Converter not Supported...")
        print("")
               
        print("Quit JCads")
        time.sleep(1)
        quit()
       




choose = str(input("Do you want start an project ?... 'Yes' or 'No' !: "))
if(choose == "Yes"):
    choose = "Yes"
    print("")
    print("Setup...")
    print("")
    time.sleep(3)
    startProject()
elif(choose == "No"):
    choose = "No"
    print("")
    print("Quit JCads...")
    time.sleep(1)
    quit()
else:
    print("Start Project or Quit JCads...")

This is an script to write this program in python 3.6.2, but i want to write my own error if my
user of my program typ an failed file name (or try to load his image, including extension).

Now python give an python error, not my own error... it happens if you try to save your
edited image without extension... it give an python error and not my own error. I used
excacly an IOError, but it don't works...

Can anyone help me with my code ?... thanks, Jamie. ]]>
Python Programming JamieVanCadsand http://forums.devshed.com/python-programming-11/jcads-converter-error-found-979331.html
Simple cli menu quits on selection http://forums.devshed.com/python-programming/979307-simple-cli-menu-quits-selection-new-post.html Mon, 23 Oct 2017 19:03:06 GMT Hello, First day on Python :) I was looking to create a simple cli sample menu for my Ubuntu 17.10 and default Python 3.6.3 and i end up to this one: Code: --------- #!/usr/bin/env python Hello,

First day on Python :)

I was looking to create a simple cli sample menu for my Ubuntu 17.10 and default Python 3.6.3 and i end up to this one:

Code:

#!/usr/bin/env python
 
def menu():
    print ("Welcome, \n 1. Print Hello \n 2. Print World \n 3. Print Python \n 4. Print Hello World")
    choice = input()
 
    if choice == "1":
        print("Hello")
        menu()
 
    if choice == "2":
        print("World")
        menu()
 
    if choice == "3":
        print("Python")
        menu()
 
    if choice == "4":
        print("Hello World")
        menu()
 
 
menu()

hen i run it from terminal the menu appear with no issues but when i add a selection it quits to command prompt with no errors :(

Any help?

Thank you ]]>
Python Programming pamamolf http://forums.devshed.com/python-programming-11/simple-cli-menu-quits-selection-979307.html
first sets http://forums.devshed.com/python-programming/979297-sets-new-post.html Sat, 21 Oct 2017 00:04:57 GMT p.py && chmod +x p.py && ./p.py < latexp2clean.y ''' This program produces `first' sets from a...]]> I've found a few online programs to generate first and follow sets from Backus-Naur form expressed as yacc (bison) grammars. They haven't worked for any but tiny examples. This program generates the first sets for bigger grammars.
Code:

#! /usr/bin/python3
# expand first.py > p.py && chmod +x p.py && ./p.py < latexp2clean.y

'''
    This program produces `first' sets from a yacc grammar definition.
    Prepare the input from a yacc grammar
    1) change empty productions to EPSILON
    2) remove c source from the rules section.
    3) rules start following the %% line as one would expect.

    bash use:

        $ chmod +x first.py
        $ ./first.py grammar.yacc

    Sample input (taken from my test suite, not included)
   
FIRST(S)={a,b,c}
FIRST(A)={a,EPSILON}
FIRST(B)={b,EPSILON}
FIRST(C)={c}
FIRST(D)={d,EPSILON}
FIRST(E)={e,EPSILON}
%%
S : A B C D E ;
A : a | EPSILON ;
B : b | EPSILON ;
C : c ;
D : d | EPSILON ;
E : e | EPSILON ;
%%
FOLLOW(S)={$}
FOLLOW(A)={b,c}
FOLLOW(B)={c}
FOLLOW(C)={d,e,$}
FOLLOW(D)={e,$}
FOLLOW(E)={$}

'''

import sys, collections, pprint, re, pdb

EPSILON = 'EPSILON'
epsilon = [EPSILON]
sepsilon = set(epsilon)

class Rule:

    def __init__(self, s, split = re.compile(' *[:|] *')):
        self.str = s
        fields = split.split(s)
        self.name = fields[0]
        self.productions = [production.split() for production in fields[1:]]

    def __getitem__(self, n):
        return self.productions[n]

    def __len__(self):
        return len(self.productions)

    def __str__(self):
        return self.str

class Graph(collections.OrderedDict):

    def __init__(self, rules):
        for rule in rules:
            self[rule.name] = rule.productions
        for rule in rules: # terminals
            for production in rule.productions:
                if production != epsilon:
                    for word in production:
                        if word not in self:
                            self[word] = None

#    @memoize...
    def first(self, key):
#        pdb.set_trace()
        return self._first(key, set(), 0)

    def _first(self, key, traced, depth):
        if key in traced:
            return set()
        traced.add(key)
        productions = self[key]
        if productions is None:  # terminal
            s = {key}
        else:
#            print(depth, key, productions)
            s = set()
            emptyok = False
            for production in productions:
                if production != epsilon:
                    for rule in production:
                        firsty = self._first(rule, traced, depth + 1)
#                        print(depth, key, productions, production, rule, firsty)
                        s = s.union(firsty)
                        if EPSILON not in firsty:
                            break
                    else:
                        emptyok = True
            s = s - sepsilon
            if (epsilon in productions) or emptyok:
                s.add(EPSILON)
        return s

def get_bnf(source):
    bnf = []
    accept = False
    for line in source:
        s = line.strip()
        accept ^= s == '%%'
        if accept and s:
          bnf.append(s)
    if '%%' in bnf[0]:
        del bnf[0]
#    pdb.set_trace()
    s = ''.join(bnf)
    s = (s[:-1] if s[-1] == ';' else s).strip()
    return list(map(Rule, s.split(';')))

def construct_graph(source):
    bnf = get_bnf(source)
    graph = Graph(bnf)
    return graph

def main(source = sys.stdin):
    graph = construct_graph(source)
    pprint.pprint(graph)
#    pdb.set_trace()
    for key in graph:
        first = graph.first(key)
        if first:
            print((key, first))

if __name__ == '__main__':
    if len(sys.argv) < 2:
        main()
    else:
        for filename in sys.argv[1:]:
            with open(filename, 'rt') as source:
                main(source)

]]>
Python Programming b49P23TIvg http://forums.devshed.com/python-programming-11/sets-979297.html