Python Forum
Need help converting some code from python 2.7 to 3.5
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Need help converting some code from python 2.7 to 3.5
#1
This works great in 2.7, does not work in 3.5. I hope some one can tell me why?



import socket   #for sockets
import sys  #for exit
 
try:
    #create an AF_INET, STREAM socket (TCP)
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
except socket.error, msg:
    print ('Failed to create socket. Error code: ') + str(msg[0]) + ' , Error message : ' + msg[1]
    sys.exit();
 
print ('Socket Created')
Line 7 is the problem I think
Thank you
Reply
#2
Yes, it is indeed line 7...and 8 and 9  :)

it should look something like this:

import socket  # for sockets
import sys  # for exit

try:
    # create an AF_INET, STREAM socket (TCP)
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
except socket.error as msg:
    print('Failed to create socket. Error code: {}'.format(str(msg)))
    sys.exit()

print('Socket Created')
If it ain't broke, I just haven't gotten to it yet.
OS: Windows 10, openSuse 42.3, freeBSD 11, Raspian "Stretch"
Python 3.6.5, IDE: PyCharm 2018 Community Edition
Reply
#3
Yes, that works. Now I want to see what you did, then if you don't mind I would like to ask you a few things. Is that ok?
renny
Reply
#4
(Oct-17-2016, 11:41 PM)Blue Dog Wrote: Yes, that works. Now I want to see what you did, then if you don't mind I would like to ask you a few things. Is that ok?
renny

That's why we are here  :D  and if I can't answer it, there is a 99.99 % chance someone else can :dance:
If it ain't broke, I just haven't gotten to it yet.
OS: Windows 10, openSuse 42.3, freeBSD 11, Raspian "Stretch"
Python 3.6.5, IDE: PyCharm 2018 Community Edition
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Converting python to FileMaker DWolf 6 1,685 Sep-22-2022, 03:40 AM
Last Post: DWolf
  Converting SQL Code To Python Code Query eddywinch82 13 29,224 Feb-15-2020, 06:42 PM
Last Post: buran
  Converting python to c# benahmadi 1 2,642 Oct-22-2019, 09:50 PM
Last Post: micseydel
  converting array to and from string in python 3.7.2 srm 5 6,172 Jul-03-2019, 01:11 PM
Last Post: snippsat
  help with converting C# function to Python korenron 17 11,328 May-19-2019, 10:26 AM
Last Post: Gribouillis
  Converting R code to python mcva 2 12,513 Mar-09-2019, 04:01 PM
Last Post: mcva
  converting from c# to python peper 1 2,950 Jun-12-2018, 05:19 PM
Last Post: micseydel
  converting python script to another version gptura 5 4,711 Mar-13-2018, 12:16 PM
Last Post: gptura
  Converting handwriting into code that can be recreated kill3rcat456 2 2,612 Mar-04-2018, 02:27 AM
Last Post: kill3rcat456
  Converting Pseudocode to Python ncp511 1 5,132 Jan-16-2018, 04:34 PM
Last Post: Windspar

Forum Jump:

User Panel Messages

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