我使用
从Python 3中的套接字接收数据data = ""
...
data = s.recv(1024)
当我想要print(data)
和print (type(data))
时,它会告诉我:
b'contentofdata'
<class 'bytes'>
如何将data
转换回字符串,以便contentofdata
之后只显示print(data)
?我使用.decode
或.encode
尝试了很多,但它似乎在Python 3中不起作用。
答案 0 :(得分:1)
您可以import UIKit
import MapKit
class ViewController: UIViewController, MKMapViewDelegate {
@IBOutlet weak var mapView: MKMapView!
override func viewDidLoad() {
super.viewDidLoad()
self.mapView.delegate = self
let baseURL = NSBundle.mainBundle().bundleURL.absoluteString
let urlTemplate = baseURL.stringByAppendingString("OSM_sat_tiles/{z}/{x}/{y}.png")
//OSM_sat_tiles is the folder name which has the tiles.
let layer = MKTileOverlay(URLTemplate: urlTemplate)
layer.canReplaceMapContent = true
self.mapView.addOverlay(layer)
}
func mapView(mapView: MKMapView, rendererForOverlay overlay: MKOverlay) -> MKOverlayRenderer {
if overlay is MKTileOverlay {
let renderer = MKTileOverlayRenderer(overlay:overlay)
renderer.alpha = 0.8
return renderer
}
return MKTileOverlayRenderer(overlay: overlay)
}
}
将字节转换为字符串。