Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
print statements without ()
#1
I have been findiing sites that include examples that have print ststements that don't use (), they use "".
When I try to execute these examples they fail unless I wrap () around them. Then I think they are still not performing as the author intended.
These all have to do with html webpages that execute cgi files that execute python code.

In particular webpages with radio buttons. Here are some links to such examples:
First Example

Second Example

And there are more.

What am I missing?
I'm not going to live long enough to do all I want to do.
Reply
#2
In Python 2.x, print wasn't a function so you didn't need the parens. Those sites are out of date now, because Python 2.x is no longer supported.
Reply
#3
The code on these web site are using Python 2.
In Python 2 was print statement,not a function as it is in Python 3.
Both Python 2 and CGI are dead💀

CGI has been dead for long time in Python,and you should not at all use examples on site you link to.
CGI will be removed(Deprecated) from Python in next version.

Then modern way to do web-development in Python is to use eg Flask, Django ...ect
Flask is close to HTML/CSS with little overhead,so can say it has taken over the role CGI once had.
Reply
#4
(Jun-16-2022, 04:58 AM)snippsat Wrote: Flask is close to HTML/CSS with little overhead,so can say it has taken over the role CGI once had.
One could perhaps try pyscript, which looks somewhat experimental, as the warning says on the front page ...
Reply
#5
(Jun-16-2022, 05:34 AM)Gribouillis Wrote: One could perhaps try pyscript, which looks somewhat experimental, as the warning says on the front page ...
Yes PyScript is interesting as can run Python code directly in browser have done some testing with it.
It will have different usage in future as don't need a server,and can just distribute a singe HTML file.
i would say that still should learn basic web-development with Flask as is mature and have lot of good tutorials.
Still need some basic web-development knowledge use when use PyScript.

It's of course interesting that stuff like this run in browser.
np.html
<head>
    <script defer src="https://pyscript.net/alpha/pyscript.js"></script>    
<py-env>
  - numpy
  - matplotlib
  - pandas
</py-env> 
    
<py-script>
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np

df = pd.DataFrame(np.random.rand(10, 4), columns=["a", "b", "c", "d"])
fig, ax = plt.subplots()
df.plot.area(ax=ax)
plt
</py-script>
[Image: naMD1O.png]
Reply
#6
(Jun-16-2022, 02:48 PM)snippsat Wrote: It's of course interesting that stuff like this run in browser
I managed to run the example in linux in firefox, but it was very slow to load... I tried to download pyscript and run it locally, but it failed to build. There are no clear steps to build.
Reply
#7
I thought I posted a reply but it seems to have been lost. I said something like I can't believe that cgi is dead. There are hundreds of sites explaining how to implement it with python.

I have spent many weeks creating twoo websites using cgi. I can't abandon that work to start over.

Why hasn't this been all over the internet?

I am dismayed
I'm not going to live long enough to do all I want to do.
Reply
#8
(Jun-17-2022, 01:45 AM)petec Wrote: I thought I posted a reply but it seems to have been lost. I said something like I can't believe that cgi is dead. There are hundreds of sites explaining how to implement it with python.
Have you not look at dates of those tutorials,they are old no one make tutorials for CGI anymore.
A little history Python did know that CGI(limited to one request at time) had no future,so Python community did write an all Python solution PEP 3333.
Why is WSGI necessary
Today is all Python web-frame build on top this solution(WSGI),and CGI is not used at all.

(Jun-17-2022, 01:45 AM)petec Wrote: I have spent many weeks creating twoo websites using cgi. I can't abandon that work to start over.
It's not so hard to move code over to Flask.

(Jun-17-2022, 01:45 AM)petec Wrote: Why hasn't this been all over the internet?
It's been more a quiet transition after the first pep 333 in 2003.
People that follow web-development in Python so is this old news,but new people sometime see all the old CGI tutorials and think that is still used,
which is not at all.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Unable to combine print statements in for loop adeana 2 2,004 Jun-12-2020, 05:08 PM
Last Post: adeana
  If-Print statements on the same line ClassicalSoul 1 2,268 Jan-31-2019, 02:14 PM
Last Post: buran
  How to execute a string with multiple sqlite statements and print results? shanepy 0 2,272 Nov-20-2018, 10:19 PM
Last Post: shanepy

Forum Jump:

User Panel Messages

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