Python Forum
I need to add data types to cython conversion python to c
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
I need to add data types to cython conversion python to c
#1
This question is about Cython converting python to C, C++ code

I have tried all kinds of ways to add data types that would make my python stuff work with c. Actually C++ but that doesn't matter. I have taken these out and my code compiles. What it is used for is to correct html errors and conveniently get text and resources from the web page. I haven't even tried to add it to a C++ project because I don't think it will work as is.

this is my code:

[
from urllib.error import HTTPError
from urllib.error import URLError
import requests
from bs4 import BeautifulSoup as beus

def parseTool(aurl):
    try:
        html = requests.get(aurl)
        bsobj = beus(html, 'html.parser')
        ret = bsobj.prettify()
    except HTTPError as e:
        ret = "http error"
    except URLError as e:
        ret = "url error"
    else:
        pass
    return ret
        
        
def objectTool(aurl):
    
    try:
        ret = requests.get(aurl)
    except HTTPError as e:
        ret = "http error"
    except URLError as e:
        ret = "url error"
    else:
        pass
    return ret 
the objectTool I could use 2 of them one for text and another for the resources (like images)
Reply
#2
Not a Cython expert here but as your functions take python strings and return python strings, the documentation suggests that you should be using the unicode type.

Good_AI_User Wrote:This question is about Cython converting python to C, C++ code

This looks like a misconception about Cython. Cython makes it easy to write C, C++ extensions to Python. It does not convert Python to C, C++ code. Your code using requests and beautifulsoup won't magically become C code...
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Cython, Pandas, and Chained Assignment sawtooth500 4 254 Apr-13-2024, 04:18 AM
Last Post: sawtooth500
  What data types can I use for default values? Mark17 1 540 Oct-09-2023, 02:07 PM
Last Post: buran
  In SQL Server, mix data types. shiv11 0 889 Sep-21-2022, 12:50 PM
Last Post: shiv11
  How to insert different types of data into a function DrData82 0 1,257 Feb-10-2022, 10:41 PM
Last Post: DrData82
  unable to load an image with C (Cython) HLD202 0 1,320 Jan-13-2022, 09:16 PM
Last Post: HLD202
  Cython np.where slows down the code Johanoosterwaal 1 1,739 Sep-01-2021, 07:33 AM
Last Post: Johanoosterwaal
  How can I use Cython to protect my Python Code? TurboC 2 4,146 Dec-03-2020, 10:37 AM
Last Post: padma121
  Conversion of Oracle PL/SQL(packages, functions, procedures) to python modules. DivyaKumar 2 6,518 Jul-09-2020, 04:46 PM
Last Post: srikanth7482
  C to Python code conversion print problem anakk1n 1 2,194 May-22-2020, 04:15 PM
Last Post: deanhystad
  Python uppercase conversion conditions Jaypeng 7 2,999 Apr-29-2020, 11:24 AM
Last Post: jefsummers

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020